/** * Parse argument names from a skill's frontmatter "arguments" field. * Supports: "arg1 arg2", "arg1, arg2", "$arg1 $arg2" */ export function parseArgumentNames(raw: unknown): string[] { if (!raw) return [] const str = String(raw).trim() if (!str) return [] // Split by comma or space, strip $ prefixes return str .split(/[,\s]+/) .map((s) => s.trim().replace(/^\$/, "")) .filter(Boolean) } /** * Substitute {{arg}} placeholders in skill content with provided values. */ export function substituteArguments( content: string, args: Record ): string { let result = content for (const [key, value] of Object.entries(args)) { const patterns = [ new RegExp(`\\{\\{${key}\\}\\}`, "g"), new RegExp(`\\$\\{${key}\\}`, "g"), ] for (const pattern of patterns) { result = result.replace(pattern, value) } } return result }