UNPKG

@ooples/token-optimizer-mcp

Version:

Intelligent context window optimization for Claude Code - store content externally via caching and compression, freeing up your context window for what matters

318 lines 8.41 kB
/** * SmartCron - Intelligent Scheduled Task Management * * Track 2C - Tool #6: Scheduled task management with smart caching (85%+ token reduction) * * Capabilities: * - Cron job management (Linux/macOS) * - Windows Task Scheduler integration * - Schedule validation * - Execution history tracking * - Next run predictions * * Token Reduction Strategy: * - Cache job configurations (94% reduction) * - Incremental execution logs (85% reduction) * - Compressed schedule analysis (87% reduction) */ import { CacheEngine } from '../../core/cache-engine.js'; import { TokenCounter } from '../../core/token-counter.js'; import { MetricsCollector } from '../../core/metrics.js'; export type CronOperation = 'list' | 'add' | 'remove' | 'enable' | 'disable' | 'history' | 'predict-next' | 'validate'; export type SchedulerType = 'cron' | 'windows-task' | 'auto'; export type TaskStatus = 'enabled' | 'disabled' | 'running' | 'failed' | 'completed'; export type TriggerType = 'daily' | 'weekly' | 'monthly' | 'once' | 'custom'; export interface SmartCronOptions { operation: CronOperation; schedulerType?: SchedulerType; taskName?: string; schedule?: string; command?: string; user?: string; workingDirectory?: string; description?: string; enabled?: boolean; historyLimit?: number; predictCount?: number; useCache?: boolean; ttl?: number; } export interface CronJob { name: string; schedule: string; command: string; user?: string; enabled: boolean; lastRun?: number; nextRun?: number; status: TaskStatus; description?: string; workingDirectory?: string; environmentVars?: Record<string, string>; taskPath?: string; triggers?: TaskTrigger[]; runCount?: number; successCount?: number; failureCount?: number; lastExitCode?: number; averageRuntime?: number; } export interface TaskTrigger { type: TriggerType; schedule: string; enabled: boolean; startBoundary?: string; endBoundary?: string; } export interface ExecutionHistory { taskName: string; executions: ExecutionRecord[]; totalRuns: number; successRate: number; averageRuntime: number; lastRun?: ExecutionRecord; } export interface ExecutionRecord { timestamp: number; duration: number; exitCode: number; output?: string; error?: string; success: boolean; } export interface NextRunPrediction { taskName: string; schedule: string; nextRuns: number[]; humanReadable: string[]; timezone: string; } export interface ScheduleValidation { valid: boolean; schedule: string; errors?: string[]; warnings?: string[]; nextRun?: number; frequency?: string; parsedFields?: { minute?: string; hour?: string; dayOfMonth?: string; month?: string; dayOfWeek?: string; }; } export interface SmartCronResult { success: boolean; operation: CronOperation; data: { jobs?: CronJob[]; job?: CronJob; history?: ExecutionHistory; predictions?: NextRunPrediction; validation?: ScheduleValidation; output?: string; error?: string; }; metadata: { tokensUsed: number; tokensSaved: number; cacheHit: boolean; executionTime: number; }; } export declare class SmartCron { private cache; private tokenCounter; private metricsCollector; private platform; constructor(cache: CacheEngine, tokenCounter: TokenCounter, metricsCollector: MetricsCollector); /** * Main entry point for cron operations */ run(options: SmartCronOptions): Promise<SmartCronResult>; /** * Detect which scheduler type to use based on platform */ private detectSchedulerType; /** * List all scheduled jobs with smart caching */ private listJobs; /** * List cron jobs from crontab */ private listCronJobs; /** * Parse a crontab line into a CronJob */ private parseCronLine; /** * Generate a unique job name from schedule and command */ private generateJobName; /** * List Windows scheduled tasks */ private listWindowsTasks; /** * Parse a Windows task CSV line */ private parseWindowsTaskLine; /** * Simple CSV line parser that handles quoted values */ private parseCSVLine; /** * Map Windows task status to our TaskStatus type */ private mapWindowsStatus; /** * Add a new scheduled job */ private addJob; /** * Add a cron job to crontab */ private addCronJob; /** * Add a Windows scheduled task */ private addWindowsTask; /** * Convert cron schedule to Windows schedule format */ private convertToWindowsSchedule; /** * Remove a scheduled job */ private removeJob; /** * Remove a cron job from crontab */ private removeCronJob; /** * Remove a Windows scheduled task */ private removeWindowsTask; /** * Enable a scheduled job */ private enableJob; /** * Enable a Windows scheduled task */ private enableWindowsTask; /** * Disable a scheduled job */ private disableJob; /** * Disable a cron job by commenting it out */ private disableCronJob; /** * Disable a Windows scheduled task */ private disableWindowsTask; /** * Get execution history for a job with incremental caching */ private getHistory; /** * Fetch execution history from system logs */ private fetchExecutionHistory; /** * Predict next run times for a job with compressed analysis */ private predictNextRuns; /** * Calculate next N run times for a cron schedule */ private calculateNextRuns; /** * Calculate the next run time for a cron schedule */ private calculateNextRun; /** * Check if a value matches a cron field */ private matchesCronField; /** * Validate a cron schedule expression */ private validateSchedule; /** * Determine the frequency description from a cron schedule */ private determineFrequency; } export declare function getSmartCron(cache: CacheEngine, tokenCounter: TokenCounter, metricsCollector: MetricsCollector): SmartCron; export declare function runSmartCron(options: SmartCronOptions, cache?: CacheEngine, tokenCounter?: TokenCounter, metricsCollector?: MetricsCollector): Promise<SmartCronResult>; export declare const SMART_CRON_TOOL_DEFINITION: { name: string; description: string; inputSchema: { type: "object"; properties: { operation: { type: "string"; enum: string[]; description: string; }; schedulerType: { type: "string"; enum: string[]; description: string; }; taskName: { type: "string"; description: string; }; schedule: { type: "string"; description: string; }; command: { type: "string"; description: string; }; user: { type: "string"; description: string; }; workingDirectory: { type: "string"; description: string; }; description: { type: "string"; description: string; }; enabled: { type: "boolean"; description: string; }; historyLimit: { type: "number"; description: string; }; predictCount: { type: "number"; description: string; }; useCache: { type: "boolean"; description: string; default: boolean; }; ttl: { type: "number"; description: string; }; }; required: string[]; }; }; //# sourceMappingURL=smart-cron.d.ts.map