UNPKG

task-engine-ai-core

Version:

Revolutionary AI-driven task management system with complete transformation trilogy: Frontend v0.1.0, Backend v0.2.0, CLI v0.3.0 - Enterprise-grade performance with 95% improvements

383 lines (314 loc) • 13.2 kB
#!/usr/bin/env node /** * Simple Synchronous MCP Setup Command * * This is a simplified, synchronous version that should work reliably * across different Node.js environments. * * @version 0.5.0 * @author Task Engine AI Team */ const fs = require('fs'); const path = require('path'); function setupMCP() { console.log('šŸš€ Task Engine AI Core - MCP Setup v0.5.0 (Simple)'); console.log('===================================================\n'); try { // Add debug information console.log('šŸ” Debug info:'); console.log(` Node.js version: ${process.version}`); console.log(` Platform: ${process.platform}`); console.log(` Working directory: ${process.cwd()}`); console.log(''); const projectRoot = process.cwd(); const packageVersion = '0.5.0'; // Detect IDE const ide = detectIDE(projectRoot); console.log(`šŸ“± Detected IDE: ${ide}`); console.log(`šŸ“ Project root: ${projectRoot}`); console.log(`šŸ”§ Using npx approach for automatic package management\n`); // Create MCP configuration console.log('āš™ļø Step 1: Creating MCP configuration...'); createMCPConfig(projectRoot, ide, packageVersion); // Initialize Task Engine if needed console.log('āš™ļø Step 2: Initializing Task Engine structure...'); initializeTaskEngine(projectRoot, packageVersion); console.log('\nāœ… MCP setup completed successfully!'); console.log('\nšŸ“š Next steps:'); console.log('1. Restart your IDE to load the new MCP configuration'); console.log('2. Test the connection by asking Claude to list tasks'); console.log('3. Start using Task Engine AI through MCP!'); } catch (error) { console.error('\nāŒ Setup failed:', error.message); console.error('\nšŸ”§ Troubleshooting:'); console.error('1. Ensure you have Node.js and npm installed'); console.error('2. Check that you have write permissions in the project directory'); console.error('3. Verify your IDE supports MCP configuration'); console.error('4. Try the manual setup approach if this continues to fail'); process.exit(1); } } function detectIDE(projectRoot) { // Check for IDE-specific directories if (fs.existsSync(path.join(projectRoot, '.cursor'))) return 'cursor'; if (fs.existsSync(path.join(projectRoot, '.vscode'))) return 'vscode'; // Check environment variables if (process.env.CURSOR_USER_DATA) return 'cursor'; if (process.env.VSCODE_PID) return 'vscode'; // Default to cursor return 'cursor'; } function createMCPConfig(projectRoot, ide, packageVersion) { console.log(`āš™ļø Creating MCP configuration for ${ide}...`); const configFile = ide === 'vscode' ? '.vscode/mcp.json' : '.cursor/mcp.json'; const configDir = path.dirname(configFile); const fullConfigPath = path.join(projectRoot, configFile); const fullConfigDir = path.join(projectRoot, configDir); // Create directory if it doesn't exist if (!fs.existsSync(fullConfigDir)) { fs.mkdirSync(fullConfigDir, { recursive: true }); console.log(`šŸ“ Created directory: ${configDir}`); } // Generate configuration const config = generateMCPConfig(ide, packageVersion); // Merge with existing configuration if it exists let finalConfig = config; if (fs.existsSync(fullConfigPath)) { try { const existingConfig = JSON.parse(fs.readFileSync(fullConfigPath, 'utf8')); finalConfig = mergeConfigurations(existingConfig, config, ide); console.log(`šŸ”„ Merged with existing configuration`); } catch (error) { console.log(`āš ļø Could not parse existing config, creating new one`); } } // Write configuration file fs.writeFileSync(fullConfigPath, JSON.stringify(finalConfig, null, 2)); console.log(`āœ… Created/updated MCP configuration: ${configFile}`); } function generateMCPConfig(ide, packageVersion) { // Use the simple and efficient npx approach const baseEnv = { TASK_ENGINE_VERSION: packageVersion, TASK_ENGINE_ENVIRONMENT: 'development', TASK_ENGINE_DEBUG: 'true', TASK_ENGINE_LOG_LEVEL: 'info', MODEL: 'claude-3-5-sonnet-20241022', MAX_TOKENS: '64000', TEMPERATURE: '0.2', DEFAULT_SUBTASKS: '5', DEFAULT_PRIORITY: 'medium', ENABLE_ACTIVE_AGENT_DETECTION: 'true', ENABLE_DIRECT_TASK_CREATION: 'true', SKIP_REDUNDANT_AI_GENERATION: 'true', USE_MODERN_FOLDER_STRUCTURE: 'true', FOLDER_NAME: '.task-engine', LEGACY_COMPATIBILITY: 'true', AUTO_PROJECT_ROOT_DETECTION: 'true', ENABLE_TEMPLATE_SYSTEM: 'true', ENABLE_INTELLIGENT_INITIALIZATION: 'true' }; const serverConfig = { command: 'npx', args: ['--package=task-engine-ai-core@' + packageVersion, 'task-master-mcp'], env: baseEnv }; if (ide === 'vscode') { return { servers: { 'task-engine-ai-core': serverConfig } }; } else { return { mcpServers: { 'task-engine-ai-core': serverConfig } }; } } function mergeConfigurations(existing, newConfig, ide) { const serverKey = ide === 'vscode' ? 'servers' : 'mcpServers'; if (!existing[serverKey]) { existing[serverKey] = {}; } // Update or add the task-engine-ai-core configuration existing[serverKey]['task-engine-ai-core'] = newConfig[serverKey]['task-engine-ai-core']; return existing; } function initializeTaskEngine(projectRoot, packageVersion) { const taskEngineDir = path.join(projectRoot, '.task-engine'); if (!fs.existsSync(taskEngineDir)) { console.log('šŸ”§ Initializing Task Engine project with templates...'); try { // Create basic Task Engine structure fs.mkdirSync(taskEngineDir, { recursive: true }); fs.mkdirSync(path.join(taskEngineDir, 'tasks'), { recursive: true }); fs.mkdirSync(path.join(taskEngineDir, 'docs'), { recursive: true }); fs.mkdirSync(path.join(taskEngineDir, 'reports'), { recursive: true }); fs.mkdirSync(path.join(taskEngineDir, 'templates'), { recursive: true }); // Detect project type and name const projectType = detectProjectType(projectRoot); const projectName = getProjectName(projectRoot); // Create configuration const basicConfig = { version: packageVersion, projectRoot: projectRoot, projectName: projectName, projectType: projectType, initialized: new Date().toISOString(), setupMethod: 'simple-sync', folderStructure: 'modern', taskEngine: { version: packageVersion, environment: 'development', debug: true, logLevel: 'info', useModernStructure: true }, features: { aiAssistance: true, taskManagement: true, progressTracking: true, mcpIntegration: true } }; fs.writeFileSync( path.join(taskEngineDir, 'config.json'), JSON.stringify(basicConfig, null, 2) ); // Create empty tasks file const emptyTasks = { version: "1.0", projectName: projectName, projectType: projectType, created: new Date().toISOString(), lastModified: new Date().toISOString(), metadata: { setupMethod: 'simple-sync', taskEngineVersion: packageVersion, folderStructure: 'modern', totalTasks: 0, completedTasks: 0, pendingTasks: 0 }, tasks: [], taskCounter: 0 }; fs.writeFileSync( path.join(taskEngineDir, 'tasks', 'tasks.json'), JSON.stringify(emptyTasks, null, 2) ); // Create basic README const readmeContent = generateProjectReadme(projectName, projectType, packageVersion); fs.writeFileSync( path.join(taskEngineDir, 'docs', 'README.md'), readmeContent ); console.log('āœ… Task Engine project initialized with templates'); console.log(`šŸ“‹ Project: ${projectName} (${projectType})`); console.log('šŸ“ Created: .task-engine/ directory structure (modern)'); } catch (error) { console.log(`āš ļø Could not initialize Task Engine: ${error.message}`); } } else { console.log('ā„¹ļø Task Engine project already initialized'); } } function detectProjectType(projectRoot) { const packageJsonPath = path.join(projectRoot, 'package.json'); if (fs.existsSync(packageJsonPath)) { try { const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); const deps = { ...packageJson.dependencies, ...packageJson.devDependencies }; if (deps.react || deps['@types/react']) return 'web-app'; if (deps.express || deps.fastify || deps.koa) return 'api'; if (deps['react-native']) return 'mobile-app'; if (deps.electron) return 'desktop-app'; if (packageJson.bin) return 'cli-tool'; if (packageJson.main && !packageJson.scripts?.start) return 'library'; } catch (error) { // Ignore JSON parsing errors } } // Check for other project indicators if (fs.existsSync(path.join(projectRoot, 'requirements.txt'))) return 'api'; if (fs.existsSync(path.join(projectRoot, 'Cargo.toml'))) return 'cli-tool'; if (fs.existsSync(path.join(projectRoot, 'go.mod'))) return 'api'; return 'generic'; } function getProjectName(projectRoot) { const packageJsonPath = path.join(projectRoot, 'package.json'); if (fs.existsSync(packageJsonPath)) { try { const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); if (packageJson.name) return packageJson.name; } catch (error) { // Ignore JSON parsing errors } } // Fallback to directory name return projectRoot.split(/[/\\]/).pop() || 'My Project'; } function generateProjectReadme(projectName, projectType, packageVersion) { return `# ${projectName} A ${projectType} project powered by **Task Engine AI Core v${packageVersion}**. ## šŸ¤– Task Engine AI Integration This project includes Task Engine AI for intelligent task management and AI-assisted development. ### Getting Started with Task Engine 1. **View Tasks:** Ask Claude "Show me my current tasks" 2. **Create Tasks:** "Create a task to implement [feature]" 3. **Update Progress:** "Mark task [id] as completed" 4. **Get Help:** "Help me break down this complex feature into subtasks" ## šŸ“ Project Structure \`\`\` ${projectName}/ ā”œā”€ā”€ .task-engine/ # Task Engine AI project data │ ā”œā”€ā”€ config.json # Project configuration │ ā”œā”€ā”€ tasks/ # Task files and data │ ā”œā”€ā”€ docs/ # Project documentation │ ā”œā”€ā”€ reports/ # Progress reports and analytics │ └── templates/ # Project templates ā”œā”€ā”€ .cursor/mcp.json # Cursor IDE MCP configuration └── [your project files] \`\`\` ## šŸš€ Next Steps 1. Ask Claude to create initial tasks for your project 2. Use Task Engine for planning and progress tracking 3. Let AI assist with implementation and problem-solving --- **Powered by Task Engine AI Core v${packageVersion}** šŸš€`; } function showHelp() { console.log(` Task Engine AI Core - MCP Setup v0.5.0 (Simple) Usage: node setup-mcp-simple.js [options] Options: --help, -h Show this help message --version, -v Show version information This command sets up MCP configuration for Task Engine AI Core in the current project. Requirements: - Node.js installed - Run from your project root directory - IDE must support MCP (Cursor, VS Code, Claude Desktop) Examples: # Basic setup in current directory node setup-mcp-simple.js For more information, visit: https://github.com/cracked99/Task-engine `); } // Main execution if (require.main === module) { const args = process.argv.slice(2); if (args.includes('--help') || args.includes('-h')) { showHelp(); process.exit(0); } if (args.includes('--version') || args.includes('-v')) { console.log('Task Engine AI Core - MCP Setup v0.5.0 (Simple)'); process.exit(0); } setupMCP(); } module.exports = { setupMCP };