import { existsSync, readFileSync } from "fs"; import { resolve } from "path"; import chalk from "chalk"; import { validateSkillContent } from "../lib/validate-skill.js"; export async function validateCommand( filePath: string, options: { quiet?: boolean } ): Promise<{ valid: boolean }> { const absPath = resolve(filePath); if (!existsSync(absPath)) { console.error(chalk.red(`Error: File not found: ${absPath}`)); process.exit(1); } const content = readFileSync(absPath, "utf-8"); const result = validateSkillContent(content); if (!options.quiet) { if (result.frontmatter) { const fm = result.frontmatter; console.log(chalk.bold("\nSkill metadata:")); console.log(` Name: ${chalk.cyan(fm.name)}`); console.log(` Version: ${fm.version}`); console.log(` Author: ${fm.author}`); console.log(` Price: ${fm.price === 0 ? chalk.green("Free") : `$${(fm.price / 100).toFixed(2)}`}`); console.log(` Tags: ${fm.tags?.join(", ") || "(none)"}`); if (fm.references?.length) { console.log(` References: ${fm.references.length}`); } if (fm.required_secrets?.length) { console.log(` Required secrets: ${fm.required_secrets.join(", ")}`); } console.log(); } for (const w of result.warnings) { console.log(chalk.yellow(`⚠ ${w}`)); } for (const e of result.errors) { console.log(chalk.red(`✗ ${e}`)); } if (result.valid) { console.log(chalk.green("✓ Validation passed")); } else { console.log(chalk.red("\nValidation failed. Fix the errors above and try again.")); } } return { valid: result.valid }; }