ai-debug-local-mcp
Version:
🎯 ENHANCED AI GUIDANCE v4.1.2: Dramatically improved tool descriptions help AI users choose the right tools instead of 'close enough' options. Ultra-fast keyboard automation (10x speed), universal recording, multi-ecosystem debugging support, and compreh
434 lines • 17.4 kB
JavaScript
/**
* 🔄 Auto-Update Handler for AI-Debug MCP Server
*
* Provides MCP tools for managing auto-updates
* Ensures users always have the latest features including universal recording
*/
import { BaseToolHandler } from './base-handler.js';
import { AutoUpdater } from '../utils/auto-updater.js';
export class AutoUpdateHandler extends BaseToolHandler {
name = 'AutoUpdateHandler';
description = 'Auto-update management for AI-Debug';
autoUpdater;
updateNotifications = [];
constructor() {
super();
this.initializeAutoUpdater();
}
initializeAutoUpdater() {
// Initialize with default configuration
this.autoUpdater = new AutoUpdater({
enabled: true,
checkInterval: 6 * 60 * 60 * 1000, // 6 hours for development
channel: 'stable',
autoDownload: true,
autoInstall: false, // Require user confirmation
notifyOnly: false,
githubRepo: 'ai-debug/ai-debug-local-mcp',
preserveLocalChanges: true,
backupBeforeUpdate: true
});
// Set up event listeners
this.setupEventListeners();
}
setupEventListeners() {
this.autoUpdater.on('checking-for-update', () => {
console.log('🔄 Checking for AI-Debug updates...');
});
this.autoUpdater.on('update-available', (info) => {
console.log(`🎉 Update available: v${info.version}`);
this.updateNotifications.push(info);
// Log new features
if (info.features.length > 0) {
console.log('✨ New features:');
info.features.forEach(feature => console.log(` - ${feature}`));
}
// Log fixes
if (info.fixes.length > 0) {
console.log('🐛 Bug fixes:');
info.fixes.forEach(fix => console.log(` - ${fix}`));
}
// Alert for security patches
if (info.securityPatches) {
console.log('🔒 SECURITY UPDATE - Installation recommended!');
}
});
this.autoUpdater.on('update-not-available', () => {
console.log('✅ AI-Debug is up to date');
});
this.autoUpdater.on('download-progress', (progress) => {
console.log(`⬇️ Downloading update: ${progress.percent}%`);
});
this.autoUpdater.on('update-downloaded', (info) => {
console.log(`✅ Update downloaded: v${info.version}`);
console.log('🔄 Restart AI-Debug to apply update');
});
this.autoUpdater.on('before-install', (info) => {
console.log(`🔧 Installing update v${info.version}...`);
});
this.autoUpdater.on('update-installed', (info) => {
console.log(`✅ Update v${info.version} installed successfully!`);
console.log('🔄 Please restart AI-Debug MCP server');
});
this.autoUpdater.on('error', (error) => {
console.error('❌ Auto-update error:', error.message);
});
this.autoUpdater.on('backup-created', (backupPath) => {
console.log(`💾 Backup created at: ${backupPath}`);
});
this.autoUpdater.on('restart-required', () => {
console.log('🔄 RESTART REQUIRED: Please restart the MCP server to apply updates');
});
}
tools = [
{
name: 'check_for_updates',
description: '🔄 Check for available AI-Debug updates including new universal recording features',
inputSchema: {
type: 'object',
properties: {
channel: {
type: 'string',
enum: ['stable', 'beta', 'nightly'],
description: 'Update channel to check (default: stable)',
default: 'stable'
},
force: {
type: 'boolean',
description: 'Force check even if recently checked',
default: false
}
}
}
},
{
name: 'install_update',
description: '⬆️ Install available AI-Debug update with automatic backup',
inputSchema: {
type: 'object',
properties: {
version: {
type: 'string',
description: 'Specific version to install (optional, uses latest if not specified)'
},
backup: {
type: 'boolean',
description: 'Create backup before updating',
default: true
},
skipConfirmation: {
type: 'boolean',
description: 'Skip confirmation prompt (use with caution)',
default: false
}
}
}
},
{
name: 'configure_auto_update',
description: '⚙️ Configure auto-update settings for AI-Debug',
inputSchema: {
type: 'object',
properties: {
enabled: {
type: 'boolean',
description: 'Enable or disable auto-updates'
},
channel: {
type: 'string',
enum: ['stable', 'beta', 'nightly'],
description: 'Update channel preference'
},
autoInstall: {
type: 'boolean',
description: 'Automatically install updates without confirmation'
},
checkInterval: {
type: 'number',
description: 'Check interval in hours (minimum: 1)',
minimum: 1
},
notifyOnly: {
type: 'boolean',
description: 'Only notify about updates, do not download'
}
}
}
},
{
name: 'get_update_status',
description: '📊 Get current update status and version information',
inputSchema: {
type: 'object',
properties: {
includeHistory: {
type: 'boolean',
description: 'Include update history',
default: false
}
}
}
},
{
name: 'view_update_changelog',
description: '📋 View changelog for available update',
inputSchema: {
type: 'object',
properties: {
version: {
type: 'string',
description: 'Version to view changelog for (optional, uses latest if not specified)'
}
}
}
},
{
name: 'rollback_update',
description: '⏪ Rollback to previous version from backup',
inputSchema: {
type: 'object',
properties: {
targetVersion: {
type: 'string',
description: 'Version to rollback to'
}
},
required: ['targetVersion']
}
}
];
async handle(toolName, args) {
switch (toolName) {
case 'check_for_updates':
return await this.checkForUpdates(args);
case 'install_update':
return await this.installUpdate(args);
case 'configure_auto_update':
return await this.configureAutoUpdate(args);
case 'get_update_status':
return await this.getUpdateStatus(args);
case 'view_update_changelog':
return await this.viewUpdateChangelog(args);
case 'rollback_update':
return await this.rollbackUpdate(args);
default:
throw new Error(`Unknown tool: ${toolName}`);
}
}
async checkForUpdates(args) {
try {
// Configure channel if specified
if (args.channel) {
this.autoUpdater.configure({ channel: args.channel });
}
const updateInfo = await this.autoUpdater.checkNow();
if (updateInfo) {
return {
success: true,
updateAvailable: true,
currentVersion: this.autoUpdater.getStatus().current,
latestVersion: updateInfo.version,
releaseNotes: updateInfo.releaseNotes,
features: updateInfo.features,
fixes: updateInfo.fixes,
securityUpdate: updateInfo.securityPatches,
breaking: updateInfo.breaking,
downloadUrl: updateInfo.downloadUrl,
publishedAt: updateInfo.publishedAt,
message: `🎉 Update available: v${updateInfo.version}`
};
}
else {
const status = this.autoUpdater.getStatus();
return {
success: true,
updateAvailable: false,
currentVersion: status.current,
latestVersion: status.latest,
message: '✅ AI-Debug is up to date'
};
}
}
catch (error) {
return this.createErrorResponse(`Failed to check for updates: ${error instanceof Error ? error.message : String(error)}`);
}
}
async installUpdate(args) {
try {
if (!args.skipConfirmation) {
// In a real implementation, this would prompt the user
console.log('⚠️ Update installation requires restart. Proceed with caution.');
}
// Configure backup preference
this.autoUpdater.configure({ backupBeforeUpdate: args.backup !== false });
if (args.version) {
// Install specific version
await this.autoUpdater.installVersion(args.version);
return {
success: true,
version: args.version,
message: `✅ Successfully installed v${args.version}. Please restart AI-Debug.`
};
}
else {
// Install latest available update
const updateInfo = await this.autoUpdater.checkNow();
if (!updateInfo) {
return {
success: false,
message: 'No updates available to install'
};
}
// The auto-updater will handle the download and installation
return {
success: true,
version: updateInfo.version,
message: `🔄 Installing v${updateInfo.version}... Restart required after completion.`
};
}
}
catch (error) {
return this.createErrorResponse(`Failed to install update: ${error instanceof Error ? error.message : String(error)}`);
}
}
async configureAutoUpdate(args) {
try {
const config = {};
if (args.enabled !== undefined) {
config.enabled = args.enabled;
}
if (args.channel) {
config.channel = args.channel;
}
if (args.autoInstall !== undefined) {
config.autoInstall = args.autoInstall;
}
if (args.checkInterval) {
config.checkInterval = args.checkInterval * 60 * 60 * 1000; // Convert hours to ms
}
if (args.notifyOnly !== undefined) {
config.notifyOnly = args.notifyOnly;
}
this.autoUpdater.configure(config);
return {
success: true,
message: '✅ Auto-update configuration updated',
configuration: {
enabled: config.enabled,
channel: config.channel,
autoInstall: config.autoInstall,
checkIntervalHours: args.checkInterval,
notifyOnly: config.notifyOnly
}
};
}
catch (error) {
return this.createErrorResponse(`Failed to configure auto-update: ${error instanceof Error ? error.message : String(error)}`);
}
}
async getUpdateStatus(args) {
try {
const status = this.autoUpdater.getStatus();
const response = {
success: true,
currentVersion: status.current,
latestVersion: status.latest,
updateAvailable: status.available,
lastCheck: status.lastCheck,
checking: status.checking,
downloading: status.downloading,
installing: status.installing,
error: status.error,
progress: status.progress
};
if (args.includeHistory && this.updateNotifications.length > 0) {
response.updateHistory = this.updateNotifications.map(info => ({
version: info.version,
publishedAt: info.publishedAt,
features: info.features.length,
fixes: info.fixes.length,
security: info.securityPatches
}));
}
// Add information about new universal recording feature
if (status.current < '4.0.0' && status.latest >= '4.0.0') {
response.majorFeature = '🎬 Universal Application Recording now available!';
response.highlights = [
'Record ANY desktop application with native FFmpeg',
'Terminal/Vim workflow recording',
'AI-powered frame analysis',
'Background window automation'
];
}
return response;
}
catch (error) {
return this.createErrorResponse(`Failed to get update status: ${error instanceof Error ? error.message : String(error)}`);
}
}
async viewUpdateChangelog(args) {
try {
const version = args.version || this.autoUpdater.getStatus().latest;
// Find update info for requested version
const updateInfo = this.updateNotifications.find(info => info.version === version);
if (!updateInfo) {
// Fetch from GitHub if not in cache
const info = await this.autoUpdater.checkNow();
if (info && info.version === version) {
return {
success: true,
version: info.version,
publishedAt: info.publishedAt,
releaseNotes: info.releaseNotes,
features: info.features,
fixes: info.fixes,
breaking: info.breaking,
security: info.securityPatches
};
}
else {
return {
success: false,
message: `No changelog available for v${version}`
};
}
}
return {
success: true,
version: updateInfo.version,
publishedAt: updateInfo.publishedAt,
releaseNotes: updateInfo.releaseNotes,
features: updateInfo.features,
fixes: updateInfo.fixes,
breaking: updateInfo.breaking,
security: updateInfo.securityPatches
};
}
catch (error) {
return this.createErrorResponse(`Failed to view changelog: ${error instanceof Error ? error.message : String(error)}`);
}
}
async rollbackUpdate(args) {
try {
// This would implement rollback from backup
// For now, return a message about the feature
return {
success: false,
message: 'Rollback feature coming soon. Backups are created at ~/.ai-debug-backups/',
targetVersion: args.targetVersion
};
}
catch (error) {
return this.createErrorResponse(`Failed to rollback update: ${error instanceof Error ? error.message : String(error)}`);
}
}
/**
* Clean up resources
*/
destroy() {
if (this.autoUpdater) {
this.autoUpdater.destroy();
}
}
}
//# sourceMappingURL=auto-update-handler.js.map