// tools/create-spec/constitution-validator.ts — Constitution compliance validation.
// Extracted from create-spec.ts to keep file sizes within limits.
import { knowledgeStore } from '../../storage/index.js';
import { checkConstitutionCompliance } from '../create-spec-tech.js';
import { toolResult } from '../response-helpers.js';
/** Validates spec against Constitution principles. Returns block result or warnings. */
export async function validateConstitution(projectId, title, tags) {
    const constitution = await knowledgeStore.getConstitution(projectId);
    if (!constitution || constitution.principles.length === 0) {
        return { blocked: false, warnings: [] };
    }
    const violations = checkConstitutionCompliance(title, tags, constitution.principles);
    const strictViolations = violations.filter((v) => v.severity === 'error');
    if (strictViolations.length > 0) {
        const structured = {
            error: 'Constitution violation',
            strictViolations,
            message: `Spec violates ${strictViolations.length} strict Constitution principle(s). Revise the spec or update the Constitution.`,
        };
        return {
            blocked: true,
            errorResult: toolResult(`Constitution violation: ${structured.message}`, structured, true),
            warnings: [],
        };
    }
    return {
        blocked: false,
        warnings: violations.filter((v) => v.severity === 'warning'),
    };
}
//# sourceMappingURL=constitution-validator.js.map