/ .github / scripts / claude-enhancer-v2.js
claude-enhancer-v2.js
  1  #!/usr/bin/env node
  2  
  3  /**
  4   * Claude CV Content Enhancer v2.0 (Modular Architecture)
  5   * 
  6   * Streamlined main entry point that orchestrates modular enhancement components.
  7   * This replaces the monolithic claude-enhancer.js with a clean, maintainable architecture.
  8   * 
  9   * Architecture:
 10   * - claude-api-client.js: Handles all Claude API communication
 11   * - content-enhancers.js: Specialized enhancers for each CV section
 12   * - enhancement-orchestrator.js: Coordinates the enhancement process
 13   * 
 14   * Environment Variables:
 15   * - ANTHROPIC_API_KEY: Claude API key
 16   * - AI_BUDGET: Token budget (sufficient|limited|insufficient)
 17   * - CREATIVITY_LEVEL: Enhancement style (conservative|balanced|creative|innovative)
 18   * - ACTIVITY_SCORE: GitHub activity score for context
 19   * 
 20   * @author Adrian Wedd
 21   * @version 2.0.0
 22   */
 23  
 24  const _path = require('path');
 25  const { EnhancementOrchestrator } = require('./enhancer-modules/enhancement-orchestrator');
 26  
 27  // Configuration from environment variables and defaults
 28  const CONFIG = {
 29      ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY,
 30      AI_BUDGET: process.env.AI_BUDGET || 'sufficient',
 31      CREATIVITY_LEVEL: process.env.CREATIVITY_LEVEL || 'balanced',
 32      ACTIVITY_SCORE: parseFloat(process.env.ACTIVITY_SCORE) || 50,
 33      ENHANCEMENT_MODE: process.env.ENHANCEMENT_MODE || 'comprehensive',
 34      
 35      // API Configuration
 36      API_VERSION: '2023-06-01',
 37      MODEL: 'claude-3-5-sonnet-20241022',
 38      MAX_TOKENS: 4000,
 39      TEMPERATURE: 0.7,
 40      
 41      // Paths
 42      OUTPUT_DIR: 'data',
 43      CACHE_DIR: 'data/ai-cache',
 44      
 45      // Token Budgets by Creativity Level
 46      TOKEN_BUDGETS: {
 47          conservative: { daily: 15000, session: 4000 },
 48          balanced: { daily: 25000, session: 7000 },
 49          creative: { daily: 40000, session: 12000 },
 50          innovative: { daily: 60000, session: 18000 }
 51      }
 52  };
 53  
 54  /**
 55   * Validate configuration and environment
 56   */
 57  function validateConfiguration() {
 58      if (!CONFIG.ANTHROPIC_API_KEY) {
 59          console.error('āŒ ANTHROPIC_API_KEY environment variable required');
 60          console.error('šŸ’” Set your Claude API key: export ANTHROPIC_API_KEY="your-key-here"');
 61          process.exit(1);
 62      }
 63      
 64      if (CONFIG.AI_BUDGET === 'insufficient') {
 65          console.warn('āš ļø AI budget insufficient - using minimal enhancement mode');
 66          CONFIG.ENHANCEMENT_MODE = 'minimal';
 67      }
 68      
 69      // Adjust token limits based on creativity level
 70      const budget = CONFIG.TOKEN_BUDGETS[CONFIG.CREATIVITY_LEVEL] || CONFIG.TOKEN_BUDGETS.balanced;
 71      CONFIG.MAX_TOKENS = Math.min(CONFIG.MAX_TOKENS, budget.session / 4); // Reserve for multiple sections
 72      
 73      console.log('šŸ”§ **CONFIGURATION VALIDATED**');
 74      console.log(`   šŸ¤– Model: ${CONFIG.MODEL}`);
 75      console.log(`   šŸŽØ Creativity: ${CONFIG.CREATIVITY_LEVEL}`);
 76      console.log(`   šŸ’° Budget: ${CONFIG.AI_BUDGET}`);
 77      console.log(`   šŸ“Š Activity Score: ${CONFIG.ACTIVITY_SCORE}/100`);
 78      console.log(`   šŸŽÆ Mode: ${CONFIG.ENHANCEMENT_MODE}`);
 79      console.log('');
 80  }
 81  
 82  /**
 83   * Display usage information
 84   */
 85  function displayUsage() {
 86      console.log('šŸŽ­ **CLAUDE CV CONTENT ENHANCER v2.0**');
 87      console.log('=====================================');
 88      console.log('');
 89      console.log('šŸ“‹ **Environment Variables:**');
 90      console.log('   ANTHROPIC_API_KEY     - Your Claude API key (required)');
 91      console.log('   AI_BUDGET            - sufficient|limited|insufficient (default: sufficient)');
 92      console.log('   CREATIVITY_LEVEL     - conservative|balanced|creative|innovative (default: balanced)');
 93      console.log('   ACTIVITY_SCORE       - GitHub activity score 0-100 (default: 50)');
 94      console.log('   ENHANCEMENT_MODE     - comprehensive|activity-only|ai-only|emergency-update (default: comprehensive)');
 95      console.log('');
 96      console.log('šŸ’” **Example Usage:**');
 97      console.log('   export ANTHROPIC_API_KEY="your-key"');
 98      console.log('   export CREATIVITY_LEVEL="creative"');
 99      console.log('   node claude-enhancer-v2.js');
100      console.log('');
101      console.log('šŸ—ļø **Modular Architecture:**');
102      console.log('   šŸ“” claude-api-client.js      - API communication & caching');
103      console.log('   šŸŽØ content-enhancers.js     - Specialized section enhancers');
104      console.log('   šŸŽ­ enhancement-orchestrator.js - Process coordination');
105      console.log('');
106  }
107  
108  /**
109   * Main execution function
110   */
111  async function main() {
112      try {
113          // Display header and usage info
114          displayUsage();
115          
116          // Validate configuration
117          validateConfiguration();
118          
119          // Initialize and run orchestrator
120          console.log('šŸŽ­ **INITIALIZING ENHANCEMENT ORCHESTRATOR**');
121          const orchestrator = new EnhancementOrchestrator(CONFIG);
122          
123          console.log('šŸš€ **STARTING CV ENHANCEMENT PROCESS**');
124          const results = await orchestrator.orchestrateEnhancement();
125          
126          // Display final results
127          console.log('āœ… **ENHANCEMENT PROCESS COMPLETED SUCCESSFULLY**');
128          console.log(`šŸ“Š Final Quality Score: ${results.quality_metrics?.content_quality_score || 0}/100`);
129          console.log(`šŸŽÆ Enhancement Success Rate: ${results.quality_metrics?.enhancement_success_rate || 0}%`);
130          console.log(`šŸ’° Total Tokens Used: ${results.token_usage?.total || 0}`);
131          console.log('');
132          console.log('šŸŽ‰ **CV CONTENT ENHANCED AND READY FOR DEPLOYMENT**');
133          
134          process.exit(0);
135          
136      } catch (error) {
137          console.error('āŒ **ENHANCEMENT PROCESS FAILED**');
138          console.error(`šŸ’„ Error: ${error.message}`);
139          
140          if (error.stack && process.env.DEBUG) {
141              console.error('šŸ” Stack trace:', error.stack);
142          }
143          
144          console.error('');
145          console.error('šŸ”§ **Troubleshooting:**');
146          console.error('   1. Check your ANTHROPIC_API_KEY is valid');
147          console.error('   2. Ensure data/base-cv.json exists');
148          console.error('   3. Verify activity-summary.json is available');
149          console.error('   4. Check network connectivity');
150          console.error('   5. Review token budget limits');
151          
152          process.exit(1);
153      }
154  }
155  
156  // Handle process signals gracefully
157  process.on('SIGINT', () => {
158      console.log('\nšŸ›‘ Enhancement process interrupted by user');
159      process.exit(130);
160  });
161  
162  process.on('SIGTERM', () => {
163      console.log('\nšŸ›‘ Enhancement process terminated');
164      process.exit(143);
165  });
166  
167  // Handle uncaught errors
168  process.on('uncaughtException', (error) => {
169      console.error('šŸ’„ Uncaught exception:', error.message);
170      process.exit(1);
171  });
172  
173  process.on('unhandledRejection', (reason, _promise) => {
174      console.error('šŸ’„ Unhandled promise rejection:', reason);
175      process.exit(1);
176  });
177  
178  // Run if called directly
179  if (require.main === module) {
180      main();
181  }
182  
183  module.exports = { CONFIG };