@simonecoelhosfo/optimizely-mcp-server
Version:
Optimizely MCP Server for AI assistants with integrated CLI tools
218 lines (186 loc) • 7.02 kB
JavaScript
/**
* Documentation Registry Update System
*
* USAGE:
* node scripts/update-documentation-registry.js \
* --action "completed|created|updated|deprecated" \
* --task "Description of what was done" \
* --files "file1.md,file2.ts" \
* --impact "brief description of impact"
*
* REQUIRED FOR ALL AGENTS:
* - Run this script after completing ANY significant work
* - Provides eternal historical tracking
* - Updates both registry and context recovery
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Configuration
const REGISTRY_FILE = path.join(__dirname, '..', 'DOCUMENTATION-REGISTRY.json');
const CONTEXT_RECOVERY_FILE = path.join(__dirname, '..', 'context-recovery.md');
// Parse command line arguments
function parseArgs() {
const args = process.argv.slice(2);
const parsed = {};
for (let i = 0; i < args.length; i += 2) {
const key = args[i].replace('--', '');
const value = args[i + 1];
parsed[key] = value;
}
return parsed;
}
// Validate required arguments
function validateArgs(args) {
const required = ['action', 'task', 'files'];
const missing = required.filter(req => !args[req]);
if (missing.length > 0) {
console.error('❌ Missing required arguments:', missing.join(', '));
console.error('');
console.error('USAGE:');
console.error('node scripts/update-documentation-registry.js \\');
console.error(' --action "completed|created|updated|deprecated" \\');
console.error(' --task "Description of what was done" \\');
console.error(' --files "file1.md,file2.ts" \\');
console.error(' --impact "brief description of impact"');
process.exit(1);
}
const validActions = ['completed', 'created', 'updated', 'deprecated'];
if (!validActions.includes(args.action)) {
console.error('❌ Invalid action. Must be one of:', validActions.join(', '));
process.exit(1);
}
}
// Load existing registry or create new one
function loadRegistry() {
if (fs.existsSync(REGISTRY_FILE)) {
try {
return JSON.parse(fs.readFileSync(REGISTRY_FILE, 'utf8'));
} catch (error) {
console.warn('⚠️ Error reading registry, creating new one');
return createNewRegistry();
}
}
return createNewRegistry();
}
// Create new registry structure
function createNewRegistry() {
return {
version: "1.0.0",
created: new Date().toISOString(),
lastUpdated: new Date().toISOString(),
totalEntries: 0,
entries: [],
categories: {
documentation: 0,
implementation: 0,
testing: 0,
fixes: 0,
architecture: 0
}
};
}
// Add entry to registry
function addEntry(registry, args) {
const entry = {
id: `entry_${Date.now()}`,
timestamp: new Date().toISOString(),
action: args.action,
task: args.task,
files: args.files.split(',').map(f => f.trim()),
impact: args.impact || 'No impact specified',
agent: process.env.USER || process.env.USERNAME || 'unknown',
category: categorizeEntry(args)
};
registry.entries.unshift(entry); // Add to beginning for chronological order
registry.totalEntries = registry.entries.length;
registry.lastUpdated = entry.timestamp;
registry.categories[entry.category]++;
return entry;
}
// Categorize entry based on files and task
function categorizeEntry(args) {
const files = args.files.toLowerCase();
const task = args.task.toLowerCase();
if (files.includes('.md') || task.includes('document')) return 'documentation';
if (files.includes('test') || task.includes('test')) return 'testing';
if (task.includes('fix') || task.includes('bug')) return 'fixes';
if (files.includes('architecture') || task.includes('architecture')) return 'architecture';
return 'implementation';
}
// Save registry to file
function saveRegistry(registry) {
fs.writeFileSync(REGISTRY_FILE, JSON.stringify(registry, null, 2));
}
// Update context recovery with latest entry
function updateContextRecovery(entry) {
if (!fs.existsSync(CONTEXT_RECOVERY_FILE)) {
console.warn('⚠️ Context recovery file not found, skipping update');
return;
}
const contextContent = fs.readFileSync(CONTEXT_RECOVERY_FILE, 'utf8');
const timestamp = new Date().toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
const newEntry = `
### 🔧 ${entry.action.toUpperCase()} (${timestamp})
**TASK**: ${entry.task}
**FILES**: ${entry.files.join(', ')}
**IMPACT**: ${entry.impact}
**CATEGORY**: ${entry.category}
**REGISTRY ID**: ${entry.id}
`;
// Append to end of file
const updatedContent = contextContent + newEntry;
fs.writeFileSync(CONTEXT_RECOVERY_FILE, updatedContent);
}
// Generate summary report
function generateSummary(registry, entry) {
const recentEntries = registry.entries.slice(0, 5);
console.log('✅ DOCUMENTATION REGISTRY UPDATED');
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
console.log(`📋 Entry ID: ${entry.id}`);
console.log(`🎯 Action: ${entry.action.toUpperCase()}`);
console.log(`📝 Task: ${entry.task}`);
console.log(`📁 Files: ${entry.files.join(', ')}`);
console.log(`🏷️ Category: ${entry.category}`);
console.log(`⏰ Timestamp: ${entry.timestamp}`);
console.log('');
console.log('📊 REGISTRY STATISTICS:');
console.log(` Total Entries: ${registry.totalEntries}`);
Object.entries(registry.categories).forEach(([cat, count]) => {
console.log(` ${cat}: ${count}`);
});
console.log('');
console.log('📋 RECENT ACTIVITY:');
recentEntries.forEach(e => {
console.log(` ${e.timestamp.split('T')[0]} - ${e.action}: ${e.task.substring(0, 50)}...`);
});
console.log('');
console.log('🎯 NEXT STEPS:');
console.log(' 1. Updated context-recovery.md automatically');
console.log(' 2. Registry saved to DOCUMENTATION-REGISTRY.json');
console.log(' 3. Use "node scripts/view-registry.js" to see full history');
}
// Main execution
function main() {
console.log('🚀 DOCUMENTATION REGISTRY UPDATE SYSTEM');
console.log('═══════════════════════════════════════');
const args = parseArgs();
validateArgs(args);
const registry = loadRegistry();
const entry = addEntry(registry, args);
saveRegistry(registry);
updateContextRecovery(entry);
generateSummary(registry, entry);
console.log('✅ PROCESS COMPLETE');
}
// Run if called directly
if (import.meta.url === `file://${process.argv[1]}`) {
main();
}
export { loadRegistry, addEntry, saveRegistry };