import { isSkillEnabled } from "./config.js";
import { skillVisibleForRegisteredTools } from "./skill-tool-gating.js";
//#region src/agent/skills/format-skills-prompt.ts
/**
* Build `<available_skills>` XML block for the system prompt.
*/
function selectSkillsVisibleInPrompt(skills, skillsConfig, options) {
	let list = skills;
	if (options?.skillAllowlist?.length) {
		const allow = new Set(options.skillAllowlist.map((s) => s.toLowerCase()));
		list = list.filter((s) => allow.has(s.name.toLowerCase()));
	} else if (options?.skillAllowlist?.length === 0) return [];
	list = list.filter((s) => !s.disableModelInvocation && isSkillEnabled(s, skillsConfig));
	if (skillsConfig?.toolGating !== false && options?.registeredToolNames !== void 0) {
		const at = new Set(options.registeredToolNames);
		list = list.filter((s) => skillVisibleForRegisteredTools(s, at));
	}
	return list;
}
function escapeXml(str) {
	return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
}
function formatSkillXmlMetadataOnly(skill) {
	const emoji = skill.metadata.emoji || "";
	const emojiStr = emoji ? `${emoji} ` : "";
	return [
		"  <skill>",
		`    <name>${escapeXml(skill.name)}</name>`,
		`    <description>${emojiStr}${escapeXml(skill.description)}</description>`,
		"  </skill>"
	].join("\n");
}
function formatSkillsForPrompt(skills, skillsConfig, options) {
	const visibleSkills = selectSkillsVisibleInPrompt(skills, skillsConfig, options);
	if (visibleSkills.length === 0) return "";
	const lines = [
		"\n\n<available_skills>",
		"Skills are folders of instructions, scripts, and resources.",
		"Use skills_list to browse; use skill_view(name) for SKILL.md or skill_view(name, path) for references/, templates/, scripts/, or assets/.",
		""
	];
	for (const skill of visibleSkills) lines.push(formatSkillXmlMetadataOnly(skill));
	lines.push("</available_skills>");
	return lines.join("\n");
}
//#endregion
export { formatSkillsForPrompt, selectSkillsVisibleInPrompt };

//# sourceMappingURL=format-skills-prompt.js.map