#!/usr/bin/env node /** * Integrate Christopher Alexander Pattern Rules (inst_090-094) * * Adds the 5 Alexander pattern rules to instruction-history.json * and updates framework version from 4.2 to 4.3 * * Source: docs/governance/ALEXANDER-PATTERN-RULES.md */ const fs = require('fs'); const path = require('path'); const INSTRUCTION_HISTORY_PATH = path.join(__dirname, '../.claude/instruction-history.json'); // The 5 Alexander Pattern Rules const alexanderRules = [ { id: "inst_090", text: "Six governance services must reinforce each other through mutual validation, creating deep interlock rather than isolated enforcement", timestamp: new Date().toISOString(), quadrant: "STRATEGIC", persistence: "HIGH", temporal_scope: "PERMANENT", verification_required: "REQUIRED", explicitness: 0.90, source: "architectural_principle", session_id: "2025-10-30-alexander-integration", parameters: { services: ["BoundaryEnforcer", "CrossReferenceValidator", "MetacognitiveVerifier", "ContextPressureMonitor", "InstructionPersistenceClassifier", "PluralisticDeliberationOrchestrator"], principle: "deep_interlock" }, active: true, notes: "Centers Reinforce Centers - Deep Interlock principle from Christopher Alexander" }, { id: "inst_091", text: "Framework changes must preserve wholeness - existing audit logs remain interpretable, prior governance decisions remain valid, instruction precedents maintain authority", timestamp: new Date().toISOString(), quadrant: "STRATEGIC", persistence: "HIGH", temporal_scope: "PERMANENT", verification_required: "MANDATORY", explicitness: 0.95, source: "architectural_principle", session_id: "2025-10-30-alexander-integration", parameters: { principle: "structure_preserving_transformation", preservation_targets: ["audit_logs", "governance_decisions", "instruction_precedents"] }, active: true, notes: "Structure-Preserving Transformations Only - Enhance wholeness while maintaining coherence" }, { id: "inst_092", text: "Governance operates on gradients (NORMAL/ELEVATED/HIGH/CRITICAL context pressure, LOW/MEDIUM/HIGH persistence) rather than binary yes/no switches", timestamp: new Date().toISOString(), quadrant: "STRATEGIC", persistence: "HIGH", temporal_scope: "PERMANENT", verification_required: "REQUIRED", explicitness: 0.88, source: "architectural_principle", session_id: "2025-10-30-alexander-integration", parameters: { principle: "gradients_not_binary", examples: ["context_pressure_levels", "persistence_levels", "verification_requirements"] }, active: true, notes: "Gradients Over Binary Switches - Natural systems use gradients, not binary switches" }, { id: "inst_093", text: "Framework evolves through real-world use and feedback, not top-down specification - governance grows from failures and successes, not predetermined plans", timestamp: new Date().toISOString(), quadrant: "STRATEGIC", persistence: "HIGH", temporal_scope: "PERMANENT", verification_required: "REQUIRED", explicitness: 0.85, source: "architectural_principle", session_id: "2025-10-30-alexander-integration", parameters: { principle: "living_process", evolution_triggers: ["real_failures", "audit_log_analysis", "governance_gaps", "user_feedback"] }, active: true, notes: "Living Process Over Fixed Design - Systems grow organically through use" }, { id: "inst_094", text: "Governance must be woven into AI deployment architecture, not bolted on as separate compliance layer - if AI can execute without governance validation, framework is separate (and will be bypassed)", timestamp: new Date().toISOString(), quadrant: "STRATEGIC", persistence: "HIGH", temporal_scope: "PERMANENT", verification_required: "MANDATORY", explicitness: 0.93, source: "architectural_principle", session_id: "2025-10-30-alexander-integration", parameters: { principle: "not_separateness", integration_test: "can_ai_bypass_governance" }, active: true, notes: "Not-Separateness (Framework Integration) - Deep integration, not bolt-on compliance" } ]; function main() { console.log('═══════════════════════════════════════════════════════════'); console.log(' Integrating Christopher Alexander Pattern Rules'); console.log('═══════════════════════════════════════════════════════════\n'); // Read current instruction history let history; try { history = JSON.parse(fs.readFileSync(INSTRUCTION_HISTORY_PATH, 'utf8')); } catch (err) { console.error('❌ Error reading instruction-history.json:', err.message); process.exit(1); } console.log(`📖 Current version: ${history.version}`); console.log(` Total instructions: ${history.instructions.length}`); console.log(` Active instructions: ${history.instructions.filter(i => i.active).length}\n`); // Check if Alexander rules already exist const existingAlexander = history.instructions.filter(i => i.id >= 'inst_090' && i.id <= 'inst_094' ); if (existingAlexander.length > 0) { console.log('⚠️ Alexander rules already exist:'); existingAlexander.forEach(i => console.log(` ${i.id}: ${i.text.substring(0, 60)}...`)); console.log('\n❌ Aborting integration to prevent duplicates'); console.log(' Delete existing rules first or use a different approach\n'); process.exit(1); } // Add Alexander rules console.log('✨ Adding 5 Alexander Pattern Rules:\n'); alexanderRules.forEach(rule => { history.instructions.push(rule); console.log(` ✓ ${rule.id}: ${rule.text.substring(0, 60)}...`); }); // Update version history.version = "4.3"; history.last_updated = new Date().toISOString(); console.log(`\n📦 Updated version: ${history.version}`); console.log(` Total instructions: ${history.instructions.length}`); console.log(` Active instructions: ${history.instructions.filter(i => i.active).length}\n`); // Write back to file try { fs.writeFileSync(INSTRUCTION_HISTORY_PATH, JSON.stringify(history, null, 2), 'utf8'); } catch (err) { console.error('❌ Error writing instruction-history.json:', err.message); process.exit(1); } console.log('✅ Integration complete!\n'); console.log('═══════════════════════════════════════════════════════════'); console.log(' Next Steps:'); console.log('═══════════════════════════════════════════════════════════\n'); console.log('1. Run: node scripts/sync-instructions-to-db.js'); console.log('2. Verify framework with: node scripts/framework-stats.js'); console.log('3. Test integration with: node scripts/session-init.js\n'); } main();