vibe-coder-mcp
Version:
Production-ready MCP server with complete agent integration, multi-transport support, and comprehensive development automation tools for AI-assisted workflows.
180 lines (179 loc) • 6.87 kB
JavaScript
import logger from '../../../logger.js';
export function migrateFromLegacyContext(legacyContext, projectPath, projectName) {
const warnings = [];
const errors = [];
try {
if (!legacyContext.projectId) {
errors.push('Missing required field: projectId');
}
if (!Array.isArray(legacyContext.languages)) {
errors.push('Invalid field: languages must be an array');
}
if (!Array.isArray(legacyContext.frameworks)) {
errors.push('Invalid field: frameworks must be an array');
}
if (errors.length > 0) {
return { success: false, warnings, errors };
}
const unifiedContext = {
projectId: legacyContext.projectId,
languages: legacyContext.languages || [],
frameworks: legacyContext.frameworks || [],
tools: legacyContext.tools || [],
existingTasks: legacyContext.existingTasks || [],
codebaseSize: legacyContext.codebaseSize || 'medium',
teamSize: legacyContext.teamSize || 1,
complexity: legacyContext.complexity || 'medium',
codebaseContext: legacyContext.codebaseContext,
projectPath: projectPath || process.cwd(),
projectName: projectName || legacyContext.projectId,
description: `Migrated project: ${legacyContext.projectId}`,
buildTools: ['npm'],
configFiles: [],
entryPoints: [],
architecturalPatterns: [],
structure: {
sourceDirectories: ['src'],
testDirectories: ['test', 'tests', '__tests__'],
docDirectories: ['docs', 'documentation'],
buildDirectories: ['dist', 'build', 'lib']
},
dependencies: {
production: [],
development: [],
external: []
},
metadata: {
createdAt: new Date(),
updatedAt: new Date(),
version: '1.0.0',
source: 'manual'
}
};
if (!projectPath) {
warnings.push('projectPath not provided, using current working directory');
}
if (!projectName) {
warnings.push('projectName not provided, using projectId');
}
logger.debug({
projectId: legacyContext.projectId,
warningCount: warnings.length,
errorCount: errors.length
}, 'Migrated legacy ProjectContext to unified interface');
return {
success: true,
data: unifiedContext,
warnings,
errors
};
}
catch (error) {
errors.push(`Migration failed: ${error instanceof Error ? error.message : String(error)}`);
return { success: false, warnings, errors };
}
}
export function migrateToLegacyContext(unifiedContext) {
const warnings = [];
const errors = [];
try {
if (!unifiedContext.projectId) {
errors.push('Missing required field: projectId');
}
if (errors.length > 0) {
return { success: false, warnings, errors };
}
const legacyContext = {
projectId: unifiedContext.projectId,
languages: unifiedContext.languages || [],
frameworks: unifiedContext.frameworks || [],
tools: unifiedContext.tools || [],
existingTasks: unifiedContext.existingTasks || [],
codebaseSize: unifiedContext.codebaseSize || 'medium',
teamSize: unifiedContext.teamSize || 1,
complexity: unifiedContext.complexity || 'medium',
codebaseContext: unifiedContext.codebaseContext
};
const lostFields = [];
if (unifiedContext.projectPath)
lostFields.push('projectPath');
if (unifiedContext.projectName)
lostFields.push('projectName');
if (unifiedContext.description)
lostFields.push('description');
if (unifiedContext.buildTools?.length)
lostFields.push('buildTools');
if (unifiedContext.structure)
lostFields.push('structure');
if (unifiedContext.dependencies)
lostFields.push('dependencies');
if (unifiedContext.metadata)
lostFields.push('metadata');
if (lostFields.length > 0) {
warnings.push(`Fields lost in legacy conversion: ${lostFields.join(', ')}`);
}
logger.debug({
projectId: unifiedContext.projectId,
lostFieldCount: lostFields.length,
warningCount: warnings.length
}, 'Converted unified ProjectContext to legacy format');
return {
success: true,
data: legacyContext,
warnings,
errors
};
}
catch (error) {
errors.push(`Legacy conversion failed: ${error instanceof Error ? error.message : String(error)}`);
return { success: false, warnings, errors };
}
}
export function isLegacyProjectContext(obj) {
if (!obj || typeof obj !== 'object')
return false;
const context = obj;
return (typeof context.projectId === 'string' &&
Array.isArray(context.languages) &&
Array.isArray(context.frameworks) &&
Array.isArray(context.tools) &&
Array.isArray(context.existingTasks) &&
['small', 'medium', 'large'].includes(context.codebaseSize) &&
typeof context.teamSize === 'number' &&
['low', 'medium', 'high'].includes(context.complexity) &&
!context.projectPath &&
!context.projectName);
}
export function isUnifiedProjectContext(obj) {
if (!obj || typeof obj !== 'object')
return false;
const context = obj;
return (typeof context.projectId === 'string' &&
typeof context.projectPath === 'string' &&
typeof context.projectName === 'string' &&
Array.isArray(context.languages) &&
Array.isArray(context.frameworks) &&
Array.isArray(context.tools) &&
Array.isArray(context.existingTasks) &&
['small', 'medium', 'large'].includes(context.codebaseSize) &&
typeof context.teamSize === 'number' &&
['low', 'medium', 'high'].includes(context.complexity));
}
export function autoMigrateProjectContext(context, projectPath, projectName) {
if (isUnifiedProjectContext(context)) {
return {
success: true,
data: context,
warnings: [],
errors: []
};
}
if (isLegacyProjectContext(context)) {
return migrateFromLegacyContext(context, projectPath, projectName);
}
return {
success: false,
warnings: [],
errors: ['Unknown ProjectContext format - cannot migrate']
};
}