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

165 lines 6.76 kB
import { z } from 'zod'; import { execSync } from 'child_process'; import * as fs from 'fs/promises'; export const intelSynthesisTool = { name: 'intel_synthesis', description: 'Fuse intelligence from SIS, CSVLOD, MCP, Git, and filesystem', parameters: z.object({ sources: z.array(z.enum(['sis', 'csvlod', 'mcp', 'git', 'fs'])), synthesis_type: z.enum(['narrative', 'actionable', 'strategic']), time_window: z.string().optional().default('24h'), focus: z.string().optional() }), execute: async (args) => { const intelligence = {}; // Parallel intelligence gathering const gatherPromises = args.sources.map(async (source) => { switch (source) { case 'sis': const sisIntel = execSync('./.sis/bin/sis analyze all 3', { encoding: 'utf-8' }); const sisPulse = execSync('./.sis/bin/sis pulse', { encoding: 'utf-8' }); intelligence.sis = { analysis: sisIntel, pulse: sisPulse }; break; case 'csvlod': const projectState = await fs.readFile('./PROJECT_STATE.md', 'utf-8'); const decisionLog = await fs.readFile('./DECISION_LOG.md', 'utf-8'); intelligence.csvlod = { state: projectState, decisions: decisionLog }; break; case 'mcp': const mcpLogs = await fs.readFile('./mcp-server/logs/latest.log', 'utf-8').catch(() => ''); intelligence.mcp = { logs: mcpLogs.split('\n').slice(-100) }; break; case 'git': const gitLog = execSync('git log --oneline -20', { encoding: 'utf-8' }); const gitStatus = execSync('git status --short', { encoding: 'utf-8' }); intelligence.git = { log: gitLog, status: gitStatus }; break; case 'fs': const recentFiles = execSync('find . -type f -mmin -1440 | head -50', { encoding: 'utf-8' }); intelligence.fs = { recent: recentFiles.split('\n') }; break; } }); await Promise.all(gatherPromises); // Synthesize based on type let synthesis = ''; const confidence = calculateConfidence(intelligence); switch (args.synthesis_type) { case 'narrative': synthesis = generateNarrative(intelligence, args.focus); break; case 'actionable': synthesis = generateActionables(intelligence, args.focus); break; case 'strategic': synthesis = generateStrategic(intelligence, args.time_window); break; } // Compress using SIS const compressed = execSync(`./.sis/bin/sis compress "${synthesis}" 500`, { encoding: 'utf-8' }); return { synthesis: compressed, confidence_score: confidence, sources_analyzed: args.sources.length, blind_spots: identifyBlindSpots(intelligence), next_actions: extractNextActions(synthesis), it_score: extractITScore(compressed) }; } }; function calculateConfidence(intel) { let score = 0; let factors = 0; if (intel.sis?.pulse) { score += 0.9; factors++; } if (intel.csvlod?.state) { score += 0.8; factors++; } if (intel.git?.status === '') { score += 0.7; factors++; } return factors > 0 ? score / factors : 0; } function generateNarrative(intel, focus) { const parts = []; if (intel.sis?.pulse) { parts.push(`Current workspace state: ${intel.sis.pulse.trim()}`); } if (intel.git?.log) { const commits = intel.git.log.split('\n').slice(0, 5); parts.push(`Recent activity includes ${commits.length} commits focused on ${detectCommitPattern(commits)}`); } if (intel.csvlod?.state && focus) { const relevantSection = extractRelevantSection(intel.csvlod.state, focus); if (relevantSection) { parts.push(`CSVLOD framework indicates: ${relevantSection}`); } } return parts.join('. '); } function generateActionables(intel, focus) { const actions = []; // Check SIS analysis for issues if (intel.sis?.analysis?.includes('WARN')) { actions.push('1. Address security warnings detected by SIS'); } // Check git status if (intel.git?.status) { const modified = intel.git.status.split('\n').filter((l) => l.startsWith(' M')).length; if (modified > 5) { actions.push(`2. Commit ${modified} modified files to maintain clean state`); } } // Check for evolution proposals const evolveOutput = execSync('./.sis/bin/sis evolve low', { encoding: 'utf-8' }); if (evolveOutput.includes('EV-')) { actions.push('3. Review and execute SIS evolution proposals'); } return actions.join('\n'); } function generateStrategic(intel, timeWindow) { return `Strategic analysis over ${timeWindow}: System shows healthy evolution patterns with opportunities for optimization in security and file management.`; } function identifyBlindSpots(intel) { const blindSpots = []; if (!intel.mcp?.logs || intel.mcp.logs.length === 0) { blindSpots.push('MCP server logs unavailable'); } if (!intel.csvlod?.decisions) { blindSpots.push('Decision log not accessible'); } return blindSpots; } function extractNextActions(synthesis) { const lines = synthesis.split('\n'); return lines.filter(l => /^\d+\./.test(l)); } function extractITScore(compressed) { const match = compressed.match(/IT-Score:\s*([\d.]+)/); return match ? parseFloat(match[1]) : 0; } function detectCommitPattern(commits) { const patterns = { feat: 0, fix: 0, refactor: 0, docs: 0 }; commits.forEach(commit => { if (commit.includes('feat')) patterns.feat++; else if (commit.includes('fix')) patterns.fix++; else if (commit.includes('refactor')) patterns.refactor++; else if (commit.includes('docs')) patterns.docs++; }); const dominant = Object.entries(patterns).sort((a, b) => b[1] - a[1])[0]; return `${dominant[0]} (${dominant[1]}/${commits.length})`; } function extractRelevantSection(content, focus) { const lines = content.split('\n'); const relevantLines = lines.filter(l => l.toLowerCase().includes(focus.toLowerCase())); return relevantLines[0]?.substring(0, 100) || ''; } //# sourceMappingURL=intel-synthesis.js.map