#!/usr/bin/env node /** * Add inst_077 (session closedown script invocation) * and deprecate inst_024_CONSOLIDATED * * This script adds the new instruction to replace manual closedown with automated script */ const fs = require('fs'); const path = require('path'); const INSTRUCTION_HISTORY_PATH = path.join(__dirname, '../.claude/instruction-history.json'); function main() { console.log('Loading instruction history...'); const history = JSON.parse(fs.readFileSync(INSTRUCTION_HISTORY_PATH, 'utf8')); // Check if inst_077 already exists const existing = history.instructions.find(i => i.id === 'inst_077'); if (existing) { console.log('⚠️ inst_077 already exists - updating instead'); } // Find inst_024_CONSOLIDATED to deprecate const inst024Consolidated = history.instructions.find(i => i.id === 'inst_024_CONSOLIDATED'); if (!inst024Consolidated) { console.error('❌ Could not find inst_024_CONSOLIDATED'); process.exit(1); } if (!inst024Consolidated.active) { console.log('✓ inst_024_CONSOLIDATED already deprecated'); } else { console.log('Deprecating inst_024_CONSOLIDATED...'); inst024Consolidated.active = false; inst024Consolidated.deprecated_date = new Date().toISOString().split('T')[0]; inst024Consolidated.deprecated_session = '2025-10-24-session-management-automation'; inst024Consolidated.deprecation_reason = 'Replaced by executable script (session-closedown.js) invoked via inst_077. Manual procedure now automated with framework analysis and rule suggestions.'; } // Create inst_077 const inst077 = { id: 'inst_077', text: 'When user requests session closedown (or says "wrap up", "end session", "create handoff", "process session closedown"), execute: `node scripts/session-closedown.js`. Script will handle all closedown phases: (1) Kill background processes, (2) Sync instructions to database, (3) Framework performance analysis, (4) Audit log analysis with rule suggestions, (5) Git status documentation, (6) Handoff document creation, (7) Compaction marker creation. STOP ALL WORK after script completes. Do NOT continue working or respond beyond acknowledging completion. Script output includes next session startup instructions.', timestamp: new Date().toISOString(), quadrant: 'OPERATIONAL', persistence: 'HIGH', temporal_scope: 'PERMANENT', verification_required: 'MANDATORY', explicitness: 0.98, source: 'framework', session_id: '2025-10-24-session-management-automation', parameters: { trigger_phrases: [ 'wrap up', 'end session', 'create handoff', 'process session closedown', 'session closedown' ], script_path: 'scripts/session-closedown.js', post_script_action: 'STOP_ALL_WORK', script_phases: [ 'cleanup', 'framework_analysis', 'audit_analysis', 'git_documentation', 'handoff_creation', 'compaction_marker' ], replaces: 'inst_024_CONSOLIDATED' }, active: true, notes: 'Replaces inst_024_CONSOLIDATED (and all inst_024 series) with executable session-closedown.js script. Script provides: automated cleanup, framework performance metrics, audit log analysis, violation pattern detection, rule suggestions (3+ occurrences threshold), git status capture, comprehensive handoff document generation, compaction marker for post-restart detection. Ensures consistency across all session closedowns, reduces manual errors, provides framework intelligence.', created_date: new Date().toISOString().split('T')[0], replaces: ['inst_024_CONSOLIDATED', 'inst_024', 'inst_024a', 'inst_024b', 'inst_024c', 'inst_024d', 'inst_024e'], implementation: 'scripts/session-closedown.js', related_script: 'scripts/session-init.js (detects compaction marker)', architecture_doc: 'docs/SESSION_MANAGEMENT_ARCHITECTURE.md' }; if (existing) { // Update existing const index = history.instructions.findIndex(i => i.id === 'inst_077'); history.instructions[index] = inst077; console.log('✓ Updated inst_077'); } else { // Add new history.instructions.push(inst077); console.log('✓ Added inst_077'); } // Update metadata history.metadata = history.metadata || {}; history.metadata.last_updated = new Date().toISOString(); history.metadata.total_instructions = history.instructions.filter(i => i.active).length; // Save console.log('Saving instruction history...'); fs.writeFileSync( INSTRUCTION_HISTORY_PATH, JSON.stringify(history, null, 2) ); console.log(''); console.log('✅ SUCCESS'); console.log(''); console.log('Changes:'); console.log(' ✓ inst_077 created/updated (ACTIVE)'); console.log(' ✓ inst_024_CONSOLIDATED deprecated'); console.log(''); console.log('Next steps:'); console.log(' 1. Run: node scripts/sync-instructions-to-db.js --force'); console.log(' 2. Verify sync: Check governance admin UI'); console.log(' 3. Test: User says "process session closedown"'); console.log(''); } main();