pame-core-cli
Version:
PAME.AI Core Operating System CLI - Open Source AI Platform for Agentic Commerce
188 lines ⢠8.65 kB
JavaScript
import { Command } from 'commander';
import chalk from 'chalk';
import inquirer from 'inquirer';
import { GoogleCalendarService } from '../services/google-calendar.service.js';
import { createPanel, createTips } from '../utils/cli-ui.js';
export const calendarCommand = new Command('calendar')
.description('šļø Google Calendar integration for development workflows')
.option('--schedule <datetime>', 'Schedule deployment at specific time (ISO format)')
.option('--duration <minutes>', 'Duration in minutes (default: 60)', '60')
.option('--team <emails>', 'Team member emails (comma-separated)')
.option('--optimal', 'Find optimal deployment time for the team')
.option('--check', 'Check team availability for next 24 hours')
.option('--list', 'List upcoming calendar events')
.action(async (options) => {
try {
console.log(createPanel('šļø PAME Core Calendar Integration\n' +
'Smart scheduling for development workflows', { type: 'info', title: 'Calendar Management' }));
const calendarService = new GoogleCalendarService();
await calendarService.initialize();
const teamEmails = options.team || process.env.PAME_TEAM_EMAILS?.split(',') || [];
if (options.list) {
await handleListEvents(calendarService);
}
else if (options.check) {
await handleCheckAvailability(calendarService, teamEmails);
}
else if (options.optimal) {
await handleOptimalScheduling(calendarService, teamEmails, parseInt(options.duration?.toString() || '60'));
}
else if (options.schedule) {
await handleScheduleDeployment(calendarService, options.schedule, parseInt(options.duration?.toString() || '60'), teamEmails);
}
else {
await handleInteractiveMode(calendarService, teamEmails);
}
}
catch (error) {
console.error(chalk.red('Calendar command failed:'), error);
process.exit(1);
}
});
async function handleListEvents(calendarService) {
console.log(chalk.cyan('\nš
Upcoming Calendar Events:'));
const events = await calendarService.getUpcomingEvents(10);
if (events.length === 0) {
console.log(chalk.gray('No upcoming events found.'));
return;
}
events.forEach(event => {
const startTime = new Date(event.start.dateTime).toLocaleString();
console.log(chalk.white(`\n⢠${event.summary}`));
console.log(chalk.gray(` ${startTime}`));
if (event.description) {
console.log(chalk.gray(` ${event.description}`));
}
if (event.attendees) {
console.log(chalk.gray(` Attendees: ${event.attendees.map(a => a.email).join(', ')}`));
}
});
}
async function handleCheckAvailability(calendarService, teamEmails) {
console.log(chalk.cyan('\nš Checking Team Availability (Next 24 Hours):'));
const now = new Date();
const tomorrow = new Date(now.getTime() + 24 * 60 * 60 * 1000);
const availability = await calendarService.checkTeamAvailability(now.toISOString(), tomorrow.toISOString(), teamEmails);
if (availability.available) {
console.log(chalk.green('ā
Team is available for the next 24 hours!'));
}
else {
console.log(chalk.yellow('ā ļø Team has conflicts:'));
availability.conflictingEvents.forEach(event => {
const start = new Date(event.start.dateTime).toLocaleString();
const end = new Date(event.end.dateTime).toLocaleString();
console.log(chalk.red(` ⢠${event.summary}: ${start} - ${end}`));
});
}
}
async function handleOptimalScheduling(calendarService, teamEmails, duration) {
console.log(chalk.cyan('\nšÆ Finding Optimal Deployment Time:'));
try {
const optimalTime = await calendarService.findOptimalDeploymentTime(teamEmails, duration, 7 // Search next 7 days
);
const startTime = new Date(optimalTime.start).toLocaleString();
const endTime = new Date(optimalTime.end).toLocaleString();
console.log(createPanel(`šÆ Optimal deployment window found!\n\n` +
`š
Start: ${startTime}\n` +
`š
End: ${endTime}\n` +
`ā±ļø Duration: ${duration} minutes\n` +
`š„ Team: ${teamEmails.join(', ')}`, { type: 'success', title: 'Optimal Time Found' }));
const { shouldSchedule } = await inquirer.prompt([
{
type: 'confirm',
name: 'shouldSchedule',
message: 'Would you like to schedule this deployment?',
default: true
}
]);
if (shouldSchedule) {
const eventId = await calendarService.scheduleDeployment('PAME.AI Production Deployment', 'Automated deployment scheduled by pame-core-cli', optimalTime.start, duration, teamEmails);
console.log(chalk.green(`ā
Deployment scheduled! Calendar event ID: ${eventId}`));
}
}
catch (error) {
console.log(chalk.red('ā Could not find optimal deployment time.'));
console.log(chalk.yellow('Consider scheduling manually or expanding the search window.'));
}
}
async function handleScheduleDeployment(calendarService, scheduledTime, duration, teamEmails) {
console.log(chalk.cyan('\nš
Scheduling Deployment:'));
const eventId = await calendarService.scheduleDeployment('PAME.AI Production Deployment', 'Scheduled deployment via pame-core-cli', scheduledTime, duration, teamEmails);
console.log(createPanel(`š
Deployment scheduled successfully!\n\n` +
`š Time: ${new Date(scheduledTime).toLocaleString()}\n` +
`ā±ļø Duration: ${duration} minutes\n` +
`š„ Team: ${teamEmails.join(', ')}\n` +
`š Event ID: ${eventId}`, { type: 'success', title: 'Deployment Scheduled' }));
}
async function handleInteractiveMode(calendarService, teamEmails) {
console.log(chalk.cyan('\nš¤ Interactive Calendar Mode:'));
const { action } = await inquirer.prompt([
{
type: 'list',
name: 'action',
message: 'What would you like to do?',
choices: [
{ name: 'š
List upcoming events', value: 'list' },
{ name: 'š Check team availability', value: 'check' },
{ name: 'šÆ Find optimal deployment time', value: 'optimal' },
{ name: 'š Schedule custom deployment', value: 'custom' }
]
}
]);
switch (action) {
case 'list':
await handleListEvents(calendarService);
break;
case 'check':
await handleCheckAvailability(calendarService, teamEmails);
break;
case 'optimal':
await handleOptimalScheduling(calendarService, teamEmails, 60);
break;
case 'custom':
await handleCustomScheduling(calendarService, teamEmails);
break;
}
}
async function handleCustomScheduling(calendarService, teamEmails) {
const answers = await inquirer.prompt([
{
type: 'input',
name: 'title',
message: 'Deployment title:',
default: 'PAME.AI Production Deployment'
},
{
type: 'input',
name: 'description',
message: 'Description:',
default: 'Scheduled via pame-core-cli'
},
{
type: 'input',
name: 'datetime',
message: 'Date and time (YYYY-MM-DD HH:MM):',
validate: (input) => {
const date = new Date(input);
return date.toString() !== 'Invalid Date' || 'Please enter a valid date and time';
}
},
{
type: 'number',
name: 'duration',
message: 'Duration in minutes:',
default: 60
}
]);
const eventId = await calendarService.scheduleDeployment(answers.title, answers.description, new Date(answers.datetime).toISOString(), answers.duration, teamEmails);
console.log(chalk.green(`ā
Custom deployment scheduled! Event ID: ${eventId}`));
}
// Tips for calendar integration
const calendarTips = [
'Set PAME_TEAM_EMAILS environment variable for default team members',
'Use --optimal flag to find the best deployment time automatically',
'Check team availability before scheduling critical deployments',
'Calendar events include deployment details and team notifications'
];
console.log(createTips(calendarTips));
//# sourceMappingURL=calendar.js.map