#!/usr/bin/env node /** * Add inst_083: Handoff Auto-Injection * * Adds instruction documenting the architectural enforcement * of handoff document reading via session-init.js auto-injection. */ const fs = require('fs'); const path = require('path'); const INSTRUCTION_HISTORY_PATH = path.join(__dirname, '../.claude/instruction-history.json'); // New instruction const inst_083 = { "id": "inst_083", "text": "session-init.js MUST automatically extract and display handoff context from SESSION_CLOSEDOWN_*.md files. Prevents 27027-style pattern recognition failures where Claude skips reading handoff documents. Architectural enforcement: handoff context auto-injected into session-init output (section 1a), displaying priorities, recent work, known issues, and cleanup status. No voluntary compliance needed - information appears in context automatically.", "timestamp": new Date().toISOString(), "quadrant": "SYSTEM", "persistence": "HIGH", "temporal_scope": "PERMANENT", "verification_required": "MANDATORY", "explicitness": 0.98, "source": "framework", "session_id": "2025-10-25-handoff-auto-injection", "parameters": { "script": "scripts/session-init.js", "section": "1a", "handoff_pattern": "SESSION_CLOSEDOWN_*.md", "extracted_sections": [ "priorities", "recent_commits", "known_issues", "cleanup_summary" ], "enforcement_type": "architectural" }, "active": true, "notes": "Architectural prevention of handoff skipping. Addresses observed failure where Claude ran session-init but didn't read SESSION_CLOSEDOWN_2025-10-25.md, missing context about RESEARCH_DOCUMENTATION_PLAN.md and previous session priorities. Auto-injection makes handoff unavoidable." }; try { // Load instruction history const history = JSON.parse(fs.readFileSync(INSTRUCTION_HISTORY_PATH, 'utf8')); // Check if inst_083 already exists const exists = history.instructions.some(i => i.id === 'inst_083'); if (exists) { console.log('⚠️ inst_083 already exists - skipping'); process.exit(0); } // Add instruction history.instructions.push(inst_083); // Update metadata history.last_updated = new Date().toISOString(); history.version = "4.1"; // Update stats if (!history.stats) { history.stats = { total_instructions: 0, active_instructions: 0, by_quadrant: {}, by_persistence: {} }; } const activeInstructions = history.instructions.filter(i => i.active); history.stats.total_instructions = history.instructions.length; history.stats.active_instructions = activeInstructions.length; // Recalculate quadrant stats history.stats.by_quadrant = {}; activeInstructions.forEach(inst => { history.stats.by_quadrant[inst.quadrant] = (history.stats.by_quadrant[inst.quadrant] || 0) + 1; }); // Recalculate persistence stats history.stats.by_persistence = {}; activeInstructions.forEach(inst => { history.stats.by_persistence[inst.persistence] = (history.stats.by_persistence[inst.persistence] || 0) + 1; }); // Write back fs.writeFileSync(INSTRUCTION_HISTORY_PATH, JSON.stringify(history, null, 2)); console.log('✅ Added inst_083: Handoff Auto-Injection'); console.log(''); console.log('Stats:'); console.log(` Total instructions: ${history.stats.total_instructions}`); console.log(` Active instructions: ${history.stats.active_instructions}`); console.log(` SYSTEM quadrant: ${history.stats.by_quadrant.SYSTEM || 0}`); console.log(` HIGH persistence: ${history.stats.by_persistence.HIGH || 0}`); console.log(''); console.log('Next: Sync to database with:'); console.log(' node scripts/sync-instructions-to-db.js --force'); } catch (err) { console.error('❌ Error:', err.message); process.exit(1); }