#!/usr/bin/env node /** * Add Cache Version Enforcement Instruction * * Creates inst_075: MANDATORY cache version updates for JavaScript changes */ const fs = require('fs'); const path = require('path'); const INSTRUCTION_HISTORY_PATH = path.join(__dirname, '../.claude/instruction-history.json'); const instruction = { id: 'inst_075', instruction: 'MANDATORY: After modifying ANY JavaScript file in public/js/, you MUST run `node scripts/update-cache-version.js` to update service worker and version.json. This is NON-NEGOTIABLE.', category: 'SYSTEM', persistence: 'HIGH', quadrant: 'rules', context: { rationale: 'Browser caching WILL NOT update without service worker version bump. Users will see stale JavaScript and experience broken functionality.', enforcement: 'File write hook should WARN if .js files modified without subsequent cache version update in same session', workflow: [ '1. Modify .js file(s)', '2. IMMEDIATELY run: node scripts/update-cache-version.js', '3. Verify: git diff shows version.json, service-worker.js, and HTML files updated', '4. Commit ALL changes together' ], consequences: 'Skipping this step causes: Production outages, stale cache bugs, user frustration, rollback required' }, examples: [ { scenario: 'Modified submission-modal-enhanced.js', correct: 'Edit file → Run update-cache-version.js → Commit all changes', incorrect: 'Edit file → Commit only .js file → Deploy (USERS GET STALE CACHE)' } ], relatedInstructions: ['inst_038'], createdAt: new Date().toISOString(), createdBy: 'cache-enforcement-setup', lastValidated: new Date().toISOString() }; function addInstruction() { let history = { instructions: [] }; if (fs.existsSync(INSTRUCTION_HISTORY_PATH)) { history = JSON.parse(fs.readFileSync(INSTRUCTION_HISTORY_PATH, 'utf8')); } // Check if already exists const existing = history.instructions.find(i => i.id === 'inst_075'); if (existing) { console.log('⚠️ inst_075 already exists. Updating...'); Object.assign(existing, instruction); } else { history.instructions.push(instruction); } fs.writeFileSync(INSTRUCTION_HISTORY_PATH, JSON.stringify(history, null, 2)); console.log('\n✅ Instruction added: inst_075'); console.log('\n📋 Instruction Details:'); console.log(` ID: ${instruction.id}`); console.log(` Category: ${instruction.category}`); console.log(` Persistence: ${instruction.persistence}`); console.log(` Instruction: ${instruction.instruction}`); console.log('\n⚠️ This instruction is now ACTIVE and will be enforced by framework.\n'); } addInstruction();