/** * generate-msg CLI validate — Pure validation, no I/O */ import { GenerateMsgSpecSchema, type GenerateMsgSpec } from './types.js'; export interface ValidationResult { valid: boolean; data?: GenerateMsgSpec; blockers: string[]; warnings: string[]; } export function validate(spec: unknown): ValidationResult { const blockers: string[] = []; const warnings: string[] = []; let data: GenerateMsgSpec | undefined; try { data = GenerateMsgSpecSchema.parse(spec); } catch (err: unknown) { const e = err as any; if (e.errors) { for (const error of e.errors) { blockers.push(`${error.path?.join('.')}: ${error.message}`); } } else { blockers.push(`Spec parse failed: ${(err as Error).message}`); } return { valid: false, blockers, warnings }; } if (!data.summary.trim()) { blockers.push('summary cannot be empty'); } if (data.files.length === 0) { warnings.push('No file analysis provided — message will be generic'); } return { valid: blockers.length === 0, data, blockers, warnings }; }