* Update the mode associations for a skill by modifying its SKILL.md frontmatter. * @param name - Skill name * @param source - Where the skill is located ("global" or "project") * @param newModeSlugs - New mode slugs (undefined/empty = any mode)
(name: string, source: "global" | "project", newModeSlugs?: string[])
| 525 | * @param newModeSlugs - New mode slugs (undefined/empty = any mode) |
| 526 | */ |
| 527 | async updateSkillModes(name: string, source: "global" | "project", newModeSlugs?: string[]): Promise<void> { |
| 528 | // Find any skill with this name and source (regardless of current mode) |
| 529 | let skill: SkillMetadata | undefined |
| 530 | for (const s of this.skills.values()) { |
| 531 | if (s.name === name && s.source === source) { |
| 532 | skill = s |
| 533 | break |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | if (!skill) { |
| 538 | throw new Error(t("skills:errors.not_found", { name, source, modeInfo: "" })) |
| 539 | } |
| 540 | |
| 541 | // Read the current SKILL.md file |
| 542 | const fileContent = await fs.readFile(skill.path, "utf-8") |
| 543 | const { data: frontmatter, content: body } = matter(fileContent) |
| 544 | |
| 545 | // Update the frontmatter with new modeSlugs |
| 546 | if (newModeSlugs && newModeSlugs.length > 0) { |
| 547 | frontmatter.modeSlugs = newModeSlugs |
| 548 | // Remove legacy mode field if present |
| 549 | delete frontmatter.mode |
| 550 | } else { |
| 551 | // Empty/undefined = any mode, remove mode restrictions |
| 552 | delete frontmatter.modeSlugs |
| 553 | delete frontmatter.mode |
| 554 | } |
| 555 | |
| 556 | // Serialize back to SKILL.md format |
| 557 | const newContent = matter.stringify(body, frontmatter) |
| 558 | await fs.writeFile(skill.path, newContent, "utf-8") |
| 559 | |
| 560 | // Refresh skills list |
| 561 | await this.discoverSkills() |
| 562 | } |
| 563 | |
| 564 | /** |
| 565 | * Get all skills directories to scan, including mode-specific directories. |
no test coverage detected