import type { Skill } from "./types.ts"; export function formatSkillsForSystemPrompt(skills: Skill[]): string { const visibleSkills = skills.filter((skill) => !skill.disableModelInvocation); if (visibleSkills.length === 0) return ""; const lines = [ "The following skills provide specialized instructions for specific tasks.", "Read the full skill file when the task matches its description.", "When a skill file references a relative path, resolve it against the skill directory (parent of SKILL.md / dirname of the path) and use that absolute path in tool commands.", "", "", ]; for (const skill of visibleSkills) { lines.push(" "); lines.push(` ${escapeXml(skill.name)}`); lines.push(` ${escapeXml(skill.description)}`); lines.push(` ${escapeXml(skill.filePath)}`); lines.push(" "); } lines.push(""); return lines.join("\n"); } function escapeXml(value: string): string { return value .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); }