| 623 | /* ── Skill management ─────────────────────────────────────────── */ |
| 624 | |
| 625 | int cbm_install_skills(const char *skills_dir, bool force, bool dry_run) { |
| 626 | if (!skills_dir) { |
| 627 | return 0; |
| 628 | } |
| 629 | int count = 0; |
| 630 | |
| 631 | /* Clean up old 4-skill directories (consolidated into 1). */ |
| 632 | for (int i = 0; i < OLD_SKILL_COUNT; i++) { |
| 633 | char old_path[CLI_BUF_1K]; |
| 634 | snprintf(old_path, sizeof(old_path), "%s/%s", skills_dir, old_skill_names[i]); |
| 635 | struct stat st; |
| 636 | if (stat(old_path, &st) == 0 && S_ISDIR(st.st_mode) && !dry_run) { |
| 637 | rmdir_recursive(old_path); |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | for (int i = 0; i < CBM_SKILL_COUNT; i++) { |
| 642 | char skill_path[CLI_BUF_1K]; |
| 643 | snprintf(skill_path, sizeof(skill_path), "%s/%s", skills_dir, skills[i].name); |
| 644 | char file_path[CLI_BUF_1K]; |
| 645 | snprintf(file_path, sizeof(file_path), "%s/SKILL.md", skill_path); |
| 646 | |
| 647 | /* Check if already exists */ |
| 648 | if (!force) { |
| 649 | struct stat st; |
| 650 | if (stat(file_path, &st) == 0) { |
| 651 | continue; |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | if (dry_run) { |
| 656 | count++; |
| 657 | continue; |
| 658 | } |
| 659 | |
| 660 | if (mkdirp(skill_path, DIR_PERMS) != 0) { |
| 661 | continue; |
| 662 | } |
| 663 | |
| 664 | FILE *f = fopen(file_path, "w"); |
| 665 | if (!f) { |
| 666 | continue; |
| 667 | } |
| 668 | (void)fwrite(skills[i].content, CLI_ELEM_SIZE, strlen(skills[i].content), f); |
| 669 | (void)fclose(f); |
| 670 | count++; |
| 671 | } |
| 672 | return count; |
| 673 | } |
| 674 | |
| 675 | int cbm_remove_skills(const char *skills_dir, bool dry_run) { |
| 676 | if (!skills_dir) { |
no test coverage detected