Skip to main content
Glama
portel-dev

NCP - Natural Context Provider

by portel-dev
test-automation-powerhouse.cjsβ€’7.52 kB
#!/usr/bin/env node /** * Interactive Test: Code-Mode + Scheduler Automation Powerhouse * * This test actually creates a scheduled task, runs it, and shows the results. * Run: node tests/manual/test-automation-powerhouse.cjs */ const { spawn } = require('child_process'); const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); // ANSI colors const colors = { reset: '\x1b[0m', bright: '\x1b[1m', green: '\x1b[32m', blue: '\x1b[34m', cyan: '\x1b[36m', yellow: '\x1b[33m', red: '\x1b[31m', }; function log(message, color = 'reset') { console.log(`${colors[color]}${message}${colors.reset}`); } function header(title) { console.log('\n' + '═'.repeat(70)); log(` ${title}`, 'bright'); console.log('═'.repeat(70) + '\n'); } async function question(prompt) { return new Promise(resolve => { rl.question(`${colors.cyan}${prompt}${colors.reset} `, resolve); }); } function runCommand(args) { return new Promise((resolve, reject) => { const proc = spawn('node', ['dist/index.js', ...args], { cwd: process.cwd(), stdio: 'inherit', }); proc.on('close', code => { if (code === 0) resolve(); else reject(new Error(`Command failed with code ${code}`)); }); }); } async function main() { header('πŸš€ Automation Powerhouse Interactive Test'); log('This test will:', 'cyan'); console.log(' 1. Create a scheduled task using Code-Mode'); console.log(' 2. Show you how to monitor it'); console.log(' 3. Demonstrate the token savings'); console.log(''); const answer = await question('Ready to start? (y/n)'); if (answer.toLowerCase() !== 'y') { log('Test cancelled.', 'yellow'); rl.close(); return; } // Step 1: Show existing schedules header('πŸ“‹ Current Scheduled Tasks'); log('Listing current schedules...', 'blue'); console.log(''); try { await runCommand(['run', 'schedule:list']); } catch (error) { log('No schedules yet or error listing them.', 'yellow'); } console.log(''); await question('Press Enter to continue...'); // Step 2: Create a demo schedule header('✨ Creating Demo Automation'); log('Creating a system health monitor that runs every minute...', 'cyan'); console.log(''); const createCode = ` const os = require('os'); const health = { timestamp: new Date().toISOString(), cpu: { cores: os.cpus().length, load: os.loadavg()[0].toFixed(2) }, memory: { total: (os.totalmem() / 1024 / 1024 / 1024).toFixed(2) + ' GB', free: (os.freemem() / 1024 / 1024 / 1024).toFixed(2) + ' GB', used: ((1 - os.freemem() / os.totalmem()) * 100).toFixed(1) + '%' } }; return { status: 'healthy', ...health }; `.trim(); log('Code to be scheduled:', 'yellow'); console.log(createCode); console.log(''); const createSchedule = await question('Create this schedule? (y/n)'); if (createSchedule.toLowerCase() === 'y') { log('\nNote: You\'ll need to manually input the schedule parameters.', 'yellow'); log('Use these values:', 'cyan'); console.log(' - Name: demo-health-check'); console.log(' - Tool: ncp:code'); console.log(' - Schedule: * * * * * (every minute)'); console.log(' - Code: (paste the code above)'); console.log(''); try { await runCommand(['run', 'schedule:create']); } catch (error) { log('Error creating schedule. Continuing...', 'yellow'); } } // Step 3: Show how to monitor header('πŸ“Š Monitoring Automation'); log('You can monitor your scheduled tasks in several ways:', 'cyan'); console.log(''); console.log('1. List all schedules:'); log(' ncp run schedule:list', 'yellow'); console.log(''); console.log('2. View analytics:'); log(' ncp run analytics:overview', 'yellow'); console.log(''); console.log('3. Check specific schedule:'); log(' ncp run schedule:get --job_id demo-health-check', 'yellow'); console.log(''); console.log('4. View execution logs:'); log(' tail -f ~/.ncp/logs/schedule-demo-health-check.log', 'yellow'); console.log(''); const viewAnalytics = await question('View analytics now? (y/n)'); if (viewAnalytics.toLowerCase() === 'y') { console.log(''); try { await runCommand(['run', 'analytics:overview']); } catch (error) { log('Error viewing analytics.', 'red'); } } // Step 4: Token savings comparison header('πŸ’° Token Savings Analysis'); log('Traditional Approach (find + run):', 'yellow'); console.log(' Every execution:'); console.log(' 1. AI calls find("system health") β†’ 2000 tokens'); console.log(' 2. AI calls run(tool, params) β†’ 500 tokens'); console.log(' 3. Total per execution: β†’ 2500 tokens'); console.log(''); console.log(' Daily (1440 executions): β†’ 3,600,000 tokens'); console.log(' Monthly cost: β†’ ~$450'); console.log(''); log('Code-Mode + Scheduler:', 'green'); console.log(' One-time setup:'); console.log(' 1. AI creates schedule once β†’ 1500 tokens'); console.log(' Per execution (automated):'); console.log(' 1. Scheduler runs code β†’ 50 tokens'); console.log(' 2. Total per execution: β†’ 50 tokens'); console.log(''); console.log(' Daily (1440 executions): β†’ 72,000 tokens'); console.log(' Monthly cost: β†’ ~$9'); console.log(''); log(' πŸ’Ž SAVINGS: $441/month (98% reduction!)', 'green'); console.log(''); // Step 5: Real-world examples header('🌟 Real-World Use Cases'); log('With this automation powerhouse, you can:', 'cyan'); console.log(''); const examples = [ { title: 'πŸ“Š Data Pipeline', desc: 'Daily ETL: fetch, transform, load', savings: '$8.70/month', }, { title: 'πŸ” Health Monitoring', desc: 'Check services every 5 min', savings: '$250/month', }, { title: 'πŸ“§ Report Generation', desc: 'Weekly automated reports', savings: '$2/month', }, { title: 'πŸ€– DevOps Automation', desc: 'Deployment health & rollback', savings: '$180/month', }, { title: 'πŸ”„ API Sync', desc: 'Hourly sync with external APIs', savings: '$20/month', }, ]; examples.forEach(ex => { log(`${ex.title}`, 'cyan'); console.log(` ${ex.desc}`); log(` Savings: ${ex.savings}`, 'green'); console.log(''); }); // Step 6: Cleanup header('🧹 Cleanup'); const cleanup = await question('Remove the demo schedule? (y/n)'); if (cleanup.toLowerCase() === 'y') { log('\nTo remove, run:', 'yellow'); console.log(' ncp run schedule:delete --job_id demo-health-check'); console.log(''); } // Final message header('πŸŽ‰ Test Complete!'); log('Key Takeaways:', 'bright'); console.log(' βœ… Code-Mode + Scheduler = Automation Powerhouse'); console.log(' βœ… 98% token savings on scheduled tasks'); console.log(' βœ… Execute arbitrary code on any schedule'); console.log(' βœ… Chain multiple operations easily'); console.log(' βœ… Real-world savings: $441/month per automation'); console.log(''); log('πŸ“– Learn more: examples/automation-powerhouse.md', 'cyan'); log('πŸš€ Get started: ncp run schedule:create', 'yellow'); console.log(''); rl.close(); } main().catch(error => { console.error('Test error:', error); rl.close(); process.exit(1); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/portel-dev/ncp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server