#!/usr/bin/env node /** * Document Processing Verification - Enforces inst_039 * Pre-deployment checker for document content updates */ const fs = require('fs'); const path = require('path'); // Prohibited absolute language (inst_016/017) const PROHIBITED_TERMS = [ 'guarantee', 'guarantees', 'guaranteed', 'always', 'never', 'impossible', 'ensures 100%', 'eliminates all', 'completely prevents', 'absolute' ]; function checkServiceCount(content) { const violations = []; const lines = content.split('\n'); lines.forEach((line, idx) => { // Check for outdated "five services" references if (/\b(five|5)\s+(services|components|framework\s+services)/i.test(line)) { violations.push({ line: idx + 1, type: 'outdated_service_count', severity: 'HIGH', text: line.trim(), fix: 'Update to "six services" - PluralisticDeliberationOrchestrator is the 6th' }); } // Check for missing PluralisticDeliberationOrchestrator in service lists if (/services?.*:?\s*$/i.test(line)) { const nextLines = lines.slice(idx, idx + 10).join('\n'); const hasOtherServices = /ContextPressureMonitor|BoundaryEnforcer|MetacognitiveVerifier/i.test(nextLines); const hasPDO = /PluralisticDeliberationOrchestrator/i.test(nextLines); if (hasOtherServices && !hasPDO) { violations.push({ line: idx + 1, type: 'missing_pdo', severity: 'MEDIUM', text: line.trim(), fix: 'Add PluralisticDeliberationOrchestrator to service list' }); } } }); return violations; } function checkProhibitedTerms(content) { const violations = []; const lines = content.split('\n'); lines.forEach((line, idx) => { PROHIBITED_TERMS.forEach(term => { const regex = new RegExp(`\\b${term}\\b`, 'i'); if (regex.test(line)) { // Allow if it's in a citation or example if (line.includes('source:') || line.includes('[') || line.includes('Example:') || line.includes('Wrong:')) { return; } violations.push({ line: idx + 1, type: 'prohibited_term', severity: 'HIGH', text: line.trim(), term: term, fix: 'Replace with evidence-based language or add [NEEDS VERIFICATION]' }); } }); }); return violations; } function scanDocument(filePath) { if (!fs.existsSync(filePath)) { console.log(`⚠️ File not found: ${filePath}\n`); return { violations: [] }; } const content = fs.readFileSync(filePath, 'utf8'); const violations = [ ...checkServiceCount(content), ...checkProhibitedTerms(content) ]; return { violations }; } function main() { const files = process.argv.slice(2); if (files.length === 0) { console.log('Usage: verify-document-updates.js [file2] ...'); console.log(''); console.log('Pre-deployment document verification (inst_039)'); console.log('Checks for:'); console.log(' • Outdated "five services" references (should be "six services")'); console.log(' • Missing PluralisticDeliberationOrchestrator in service lists'); console.log(' • Prohibited absolute language (guarantee, always, never, etc.)'); process.exit(0); } console.log('\n📄 Document Processing Verification (inst_039)\n'); let totalViolations = 0; files.forEach(file => { console.log(`Checking: ${file}`); const result = scanDocument(file); if (result.violations.length > 0) { console.log(`\n❌ Found ${result.violations.length} issue(s):\n`); result.violations.forEach(v => { console.log(` Line ${v.line} [${v.severity}]: ${v.type}`); console.log(` Text: ${v.text}`); console.log(` Fix: ${v.fix}\n`); }); totalViolations += result.violations.length; } else { console.log(' ✅ No issues found\n'); } }); if (totalViolations > 0) { console.log(`\n❌ Total violations: ${totalViolations}\n`); console.log('Fix violations before deploying document updates.\n'); process.exit(1); } else { console.log('✅ All documents pass verification\n'); process.exit(0); } } main();