#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
function validateHandoff(filePath) {
const content = fs.readFileSync(filePath, 'utf8');
const lines = content.split('\n').length;
if (lines > 50) {
console.log(`❌ HANDOFF TOO LARGE: ${lines} lines (max: 50)`);
return false;
}
const readingTime = Math.ceil(lines * 0.8); // seconds estimated
if (readingTime > 30) {
console.log(`❌ READING TIME TOO LONG: ${readingTime}s (max: 30s)`);
return false;
}
// Check for required constitution components
const requiredSections = [
'HANDOFF STATUS',
'NEXT ACTIONS',
'PROVEN METHODOLOGY',
'REFERENCE DOCUMENTS',
'CRITICAL SUCCESS FACTORS'
];
for (const section of requiredSections) {
if (!content.includes(section)) {
console.log(`❌ MISSING REQUIRED SECTION: ${section}`);
return false;
}
}
console.log(`✅ CONSTITUTION COMPLIANT: ${lines} lines, ${readingTime}s reading time`);
return true;
}
function main() {
const handoffFile = process.argv[2];
if (!handoffFile) {
console.log('Usage: node enforce-constitution.js <handoff-file>');
process.exit(1);
}
if (!fs.existsSync(handoffFile)) {
console.log(`❌ FILE NOT FOUND: ${handoffFile}`);
process.exit(1);
}
const isValid = validateHandoff(handoffFile);
process.exit(isValid ? 0 : 1);
}
main();