tractatus/scripts/add-cache-enforcement-instruction.js
TheFlow 971690bb64 feat(cache): enforce mandatory cache version updates for JS changes
- Enhanced update-cache-version.js to update service worker and version.json
- Added inst_075 governance instruction (HIGH persistence)
- Integrated cache check into deployment script (Step 1/5)
- Created CACHE_MANAGEMENT_ENFORCEMENT.md documentation
- Bumped version to 0.1.1
- Updated all HTML cache parameters

BREAKING: Deployment now blocks if JS changed without cache update
2025-10-24 09:43:20 +13:00

71 lines
2.6 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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();