UNPKG

csvlod-ai-mcp-server

Version:

CSVLOD-AI MCP Server v3.0 with Quantum Context Intelligence - Revolutionary Context Intelligence Engine and Multimodal Processor for sovereign AI development

301 lines (252 loc) • 10 kB
#!/usr/bin/env node /** * CSVLOD-AI Sovereignty Check Script * * Post-installation validation that ensures: * - User sovereignty is preserved throughout installation * - No unauthorized data collection or external connections * - All user consent preferences are respected * - Full transparency about system changes * * Philosophy: "Every installation should strengthen sovereignty, never weaken it" */ const fs = require('fs'); const path = require('path'); const colors = { green: '\x1b[32m', yellow: '\x1b[33m', red: '\x1b[31m', blue: '\x1b[34m', reset: '\x1b[0m', bold: '\x1b[1m' }; class SovereigntyChecker { constructor() { this.projectRoot = process.cwd(); this.issues = []; this.warnings = []; this.recommendations = []; } async run() { console.log(`${colors.blue}${colors.bold} šŸ›”ļø CSVLOD-AI Sovereignty Check ${colors.reset} Validating installation preserves your digital sovereignty... `); try { await this.checkDataLocality(); await this.checkUserConsent(); await this.checkTransparency(); await this.checkExitFreedom(); await this.checkPrivacySettings(); await this.generateReport(); } catch (error) { console.error(`${colors.red}Sovereignty check failed:${colors.reset}`, error.message); process.exit(1); } } async checkDataLocality() { console.log('šŸ“ Checking data locality...'); // Verify data stays local by default const configPath = path.join(this.projectRoot, '.csvlod', 'config.json'); if (fs.existsSync(configPath)) { const config = JSON.parse(fs.readFileSync(configPath, 'utf-8')); if (config.dataLocation !== 'local' && config.sovereigntyLevel === 'high') { this.issues.push('High sovereignty mode requires local-only data storage'); } if (config.dataLocation === 'cloud' && !config.explicitCloudConsent) { this.issues.push('Cloud data storage requires explicit user consent'); } } else { this.warnings.push('No CSVLOD configuration found - run installation wizard'); } // Check for unauthorized external connections const packageLockPath = path.join(this.projectRoot, 'package-lock.json'); if (fs.existsSync(packageLockPath)) { const packageLock = JSON.parse(fs.readFileSync(packageLockPath, 'utf-8')); this.checkPackageDependencies(packageLock); } console.log(`${colors.green}āœ“ Data locality check completed${colors.reset}`); } async checkUserConsent() { console.log('šŸ‘¤ Checking user consent mechanisms...'); const configPath = path.join(this.projectRoot, '.csvlod', 'config.json'); if (fs.existsSync(configPath)) { const config = JSON.parse(fs.readFileSync(configPath, 'utf-8')); // Telemetry should be opt-in only if (config.telemetryOptIn === undefined) { this.warnings.push('Telemetry consent not explicitly set'); } if (config.telemetryOptIn && !config.telemetryConsentTimestamp) { this.issues.push('Telemetry enabled without consent timestamp'); } // Check for sovereignty level consent if (!config.sovereigntyLevelConfirmed) { this.warnings.push('Sovereignty level not explicitly confirmed by user'); } } console.log(`${colors.green}āœ“ User consent check completed${colors.reset}`); } async checkTransparency() { console.log('šŸ” Checking transparency requirements...'); // Verify audit logging is enabled const auditPath = path.join(this.projectRoot, '.csvlod', 'sovereignty-audit.json'); if (!fs.existsSync(auditPath)) { this.warnings.push('Sovereignty audit configuration not found'); } else { const auditConfig = JSON.parse(fs.readFileSync(auditPath, 'utf-8')); if (!auditConfig.enabled) { this.issues.push('Sovereignty audit is disabled - transparency requires audit logging'); } } // Check for telemetry transparency const telemetryConfigPath = path.join(this.projectRoot, '.csvlod', 'telemetry-config.json'); if (fs.existsSync(telemetryConfigPath)) { const telemetryConfig = JSON.parse(fs.readFileSync(telemetryConfigPath, 'utf-8')); if (telemetryConfig.enabled && !telemetryConfig.transparentLogging) { this.issues.push('Telemetry enabled without transparent logging'); } } console.log(`${colors.green}āœ“ Transparency check completed${colors.reset}`); } async checkExitFreedom() { console.log('🚪 Checking exit freedom...'); // Verify uninstall script exists const packageJsonPath = path.join(this.projectRoot, 'node_modules', 'csvlod-ai-mcp-server', 'package.json'); if (fs.existsSync(packageJsonPath)) { const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); if (!packageJson.scripts['uninstall-clean']) { this.warnings.push('Clean uninstall script not available'); } } // Check for data export capabilities const configPath = path.join(this.projectRoot, '.csvlod', 'config.json'); if (fs.existsSync(configPath)) { const config = JSON.parse(fs.readFileSync(configPath, 'utf-8')); if (!config.dataExportEnabled) { this.recommendations.push('Enable data export for complete exit freedom'); } } console.log(`${colors.green}āœ“ Exit freedom check completed${colors.reset}`); } async checkPrivacySettings() { console.log('šŸ”’ Checking privacy settings...'); const configPath = path.join(this.projectRoot, '.csvlod', 'config.json'); if (fs.existsSync(configPath)) { const config = JSON.parse(fs.readFileSync(configPath, 'utf-8')); // Check encryption settings if (config.sensitiveDataEncryption === false) { this.warnings.push('Sensitive data encryption is disabled'); } // Check anonymization if (config.telemetryOptIn && !config.anonymizeData) { this.issues.push('Telemetry enabled without data anonymization'); } // Check local-first preference if (!config.localFirstPreference) { this.recommendations.push('Consider enabling local-first preference for maximum privacy'); } } console.log(`${colors.green}āœ“ Privacy settings check completed${colors.reset}`); } checkPackageDependencies(packageLock) { // Check for packages with known privacy or sovereignty issues const suspiciousPackages = [ 'google-analytics', 'facebook-pixel', 'amplitude', 'mixpanel', 'segment' ]; if (packageLock.dependencies) { for (const [packageName, details] of Object.entries(packageLock.dependencies)) { if (suspiciousPackages.some(suspicious => packageName.includes(suspicious))) { this.warnings.push(`Potentially privacy-invasive package detected: ${packageName}`); } } } } async generateReport() { console.log(`${colors.blue}${colors.bold} šŸ“Š SOVEREIGNTY CHECK REPORT ${colors.reset}`); if (this.issues.length === 0 && this.warnings.length === 0) { console.log(`${colors.green}${colors.bold} šŸŽ‰ EXCELLENT SOVEREIGNTY SCORE! āœ… All sovereignty checks passed āœ… Your installation fully preserves digital sovereignty āœ… Complete user control and data ownership maintained ${colors.reset}`); } else { if (this.issues.length > 0) { console.log(`${colors.red}${colors.bold} āš ļø SOVEREIGNTY ISSUES FOUND: ${colors.reset}`); this.issues.forEach((issue, index) => { console.log(`${colors.red}${index + 1}. ${issue}${colors.reset}`); }); } if (this.warnings.length > 0) { console.log(`${colors.yellow}${colors.bold} ⚔ SOVEREIGNTY WARNINGS: ${colors.reset}`); this.warnings.forEach((warning, index) => { console.log(`${colors.yellow}${index + 1}. ${warning}${colors.reset}`); }); } if (this.recommendations.length > 0) { console.log(`${colors.blue}${colors.bold} šŸ’” SOVEREIGNTY RECOMMENDATIONS: ${colors.reset}`); this.recommendations.forEach((rec, index) => { console.log(`${colors.blue}${index + 1}. ${rec}${colors.reset}`); }); } } // Save report const report = { timestamp: new Date().toISOString(), issues: this.issues, warnings: this.warnings, recommendations: this.recommendations, score: this.calculateSovereigntyScore() }; const csvlodDir = path.join(this.projectRoot, '.csvlod'); if (!fs.existsSync(csvlodDir)) { fs.mkdirSync(csvlodDir, { recursive: true }); } fs.writeFileSync( path.join(csvlodDir, 'sovereignty-report.json'), JSON.stringify(report, null, 2) ); console.log(`${colors.blue} šŸ“„ Report saved to: .csvlod/sovereignty-report.json Next steps: • Run 'npm run install-wizard' to configure sovereignty settings • Use 'npm run telemetry-status' to check data collection • Run 'npm run validate-sovereignty' for ongoing monitoring ${colors.reset}`); // Exit with error if critical issues found if (this.issues.length > 0) { console.log(`${colors.red} āŒ Critical sovereignty issues detected! Please address these issues before using CSVLOD-AI tools. ${colors.reset}`); process.exit(1); } } calculateSovereigntyScore() { const totalChecks = 20; // Base number of sovereignty checks const issueWeight = 3; // Issues are heavily weighted const warningWeight = 1; // Warnings have less impact const deductions = (this.issues.length * issueWeight) + (this.warnings.length * warningWeight); const score = Math.max(0, ((totalChecks - deductions) / totalChecks) * 100); return Math.round(score); } } // Run sovereignty check if (require.main === module) { const checker = new SovereigntyChecker(); checker.run().catch(console.error); } module.exports = { SovereigntyChecker };