import path from "node:path"; import chalk from "chalk"; import { type CommandResult, success, silentFailure } from "../lib/command-result"; import { copySkills, copyWorkflows, copyActions, refreshCopiedSkills } from "../lib/distribute"; export const VALID_RESOURCES = ["skills", "workflows", "actions"] as const; export type Resource = (typeof VALID_RESOURCES)[number]; export function runUpdate(cwd: string, resources: string[]): CommandResult { console.log(chalk.bold("erp-kit update\n")); const selected: Set = resources.length === 0 ? new Set(VALID_RESOURCES) : new Set( resources.filter((r): r is Resource => (VALID_RESOURCES as readonly string[]).includes(r), ), ); if (selected.size === 0) { console.error(chalk.red(`Invalid resource. Valid: ${VALID_RESOURCES.join(", ")}`)); return silentFailure(); } if (selected.has("skills")) { const result = copySkills(path.join(cwd, ".agents", "skills")); if (result.removed > 0) { console.log(chalk.green(` Removed ${result.removed} stale erp-kit-* skills`)); } console.log(chalk.green(` Copied ${result.copied} skills to .agents/skills/`)); if (refreshCopiedSkills(cwd)) { console.log(chalk.green(` Refreshed .claude/skills/ (copy)`)); } } if (selected.has("workflows")) { const result = copyWorkflows(cwd); if (result.removed > 0) { console.log(chalk.green(` Removed ${result.removed} stale erp-kit-* workflow(s)`)); } if (result.copied > 0) { console.log(chalk.green(` Copied ${result.copied} workflow(s) to .github/workflows/`)); } } if (selected.has("actions")) { const result = copyActions(cwd); if (result.removed > 0) { console.log(chalk.green(` Removed ${result.removed} stale erp-kit-* action(s)`)); } if (result.copied > 0) { console.log(chalk.green(` Copied ${result.copied} action file(s) to .github/actions/`)); } } console.log(chalk.bold.green("\nDone!")); return success(); }