context-forge
Version:
AI orchestration platform with autonomous teams, enhancement planning, migration tools, 25+ slash commands, checkpoints & hooks. Multi-IDE: Claude, Cursor, Windsurf, Cline, Copilot
288 lines ⢠12.5 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorRecoveryService = void 0;
const chalk_1 = __importDefault(require("chalk"));
const aiIntelligenceService_1 = require("./aiIntelligenceService");
class ErrorRecoveryService {
constructor() {
this.aiService = new aiIntelligenceService_1.AIIntelligenceService();
}
async handleError(error, context) {
console.log(chalk_1.default.red.bold('\nā Error occurred:\n'));
console.log(chalk_1.default.red(`${error.message}\n`));
// Get recovery suggestions
const suggestions = await this.getRecoverySuggestions(error, context);
const actions = this.generateRecoveryActions(error, context, suggestions);
if (actions.length === 0) {
console.log(chalk_1.default.yellow('No automated recovery suggestions available.'));
console.log(chalk_1.default.gray('Please check the error message and try again.\n'));
return;
}
console.log(chalk_1.default.yellow(`š§ Found ${actions.length} potential solutions:\n`));
// Show recovery options
actions.forEach((action, index) => {
const priorityColor = this.getPriorityColor(action.priority);
console.log(chalk_1.default[priorityColor](`${index + 1}. ${action.title}`));
console.log(chalk_1.default.gray(` ${action.description}`));
console.log(chalk_1.default.gray(` ${action.automated ? 'š¤ Automated' : 'š¤ Manual'} ⢠Priority: ${action.priority}\n`));
});
// Auto-execute critical automated fixes
const criticalAutomated = actions.filter((a) => a.priority === 'critical' && a.automated);
if (criticalAutomated.length > 0) {
console.log(chalk_1.default.blue('š Attempting automated fixes...\n'));
for (const action of criticalAutomated) {
try {
console.log(chalk_1.default.gray(`Trying: ${action.title}...`));
const success = await action.action();
if (success) {
console.log(chalk_1.default.green(`ā
Fixed: ${action.title}`));
console.log(chalk_1.default.green('Recovery successful! You can now retry your command.\n'));
return;
}
else {
console.log(chalk_1.default.yellow(`ā ļø Partial fix: ${action.title}`));
}
}
catch (fixError) {
console.log(chalk_1.default.red(`ā Fix failed: ${action.title}`));
console.log(chalk_1.default.gray(` ${fixError.message}`));
}
}
}
// Show manual instructions
const manualActions = actions.filter((a) => !a.automated);
if (manualActions.length > 0) {
console.log(chalk_1.default.yellow('š Manual steps to try:'));
manualActions.forEach((action, index) => {
console.log(chalk_1.default.white(`${index + 1}. ${action.description}`));
});
console.log('');
}
// Show additional help
this.showAdditionalHelp(error, context);
}
async getRecoverySuggestions(error, context) {
try {
return await this.aiService.generateErrorRecoverySuggestions(error, JSON.stringify(context, null, 2), context.projectPath);
}
catch {
console.log(chalk_1.default.gray('Note: AI suggestions unavailable, using fallback analysis.'));
return [];
}
}
generateRecoveryActions(error, context, suggestions) {
const actions = [];
// Permission errors
if (error.message.includes('permission') || error.message.includes('EACCES')) {
actions.push({
id: 'fix-permissions',
title: 'Fix file permissions',
description: 'Update file permissions to allow read/write access',
priority: 'critical',
automated: true,
action: async () => this.fixPermissions(context.projectPath),
});
}
// Missing file errors
if (error.message.includes('ENOENT') || error.message.includes('not found')) {
actions.push({
id: 'create-missing-dirs',
title: 'Create missing directories',
description: 'Create any missing directories in the project path',
priority: 'high',
automated: true,
action: async () => this.createMissingDirectories(context.projectPath),
});
}
// Module not found errors
if (error.message.includes('Cannot find module') ||
error.message.includes('MODULE_NOT_FOUND')) {
actions.push({
id: 'install-dependencies',
title: 'Install missing dependencies',
description: 'Run npm install to install missing packages',
priority: 'high',
automated: true,
action: async () => this.installDependencies(context.projectPath),
});
}
// Configuration errors
if (error.message.includes('config') || error.message.includes('configuration')) {
actions.push({
id: 'reset-config',
title: 'Reset configuration',
description: 'Clear any cached configuration and use defaults',
priority: 'medium',
automated: true,
action: async () => this.resetConfiguration(context.projectPath),
});
}
// API/Network errors
if (error.message.includes('fetch') ||
error.message.includes('network') ||
error.message.includes('timeout')) {
actions.push({
id: 'retry-with-fallback',
title: 'Use offline mode',
description: 'Retry the operation without AI features or external dependencies',
priority: 'medium',
automated: false,
action: async () => true,
});
}
// Add AI suggestions as actions
suggestions.forEach((suggestion, index) => {
if (suggestion.priority === 'high') {
actions.push({
id: `ai-suggestion-${index}`,
title: suggestion.title,
description: suggestion.description,
priority: 'high',
automated: false,
action: async () => true,
});
}
});
// Sort by priority
return actions.sort((a, b) => {
const priorityOrder = { critical: 0, high: 1, medium: 2, low: 3 };
return priorityOrder[a.priority] - priorityOrder[b.priority];
});
}
async fixPermissions(projectPath) {
try {
const { exec } = await Promise.resolve().then(() => __importStar(require('child_process')));
const { promisify } = await Promise.resolve().then(() => __importStar(require('util')));
const execAsync = promisify(exec);
await execAsync(`chmod -R 755 "${projectPath}"`);
return true;
}
catch {
return false;
}
}
async createMissingDirectories(projectPath) {
try {
const fs = await Promise.resolve().then(() => __importStar(require('fs-extra')));
await fs.ensureDir(projectPath);
return true;
}
catch {
return false;
}
}
async installDependencies(projectPath) {
try {
const { exec } = await Promise.resolve().then(() => __importStar(require('child_process')));
const { promisify } = await Promise.resolve().then(() => __importStar(require('util')));
const execAsync = promisify(exec);
const fs = await Promise.resolve().then(() => __importStar(require('fs-extra')));
const path = await Promise.resolve().then(() => __importStar(require('path')));
// Check if package.json exists
const packageJsonPath = path.join(projectPath, 'package.json');
if (await fs.pathExists(packageJsonPath)) {
await execAsync('npm install', { cwd: projectPath });
return true;
}
return false;
}
catch {
return false;
}
}
async resetConfiguration(projectPath) {
try {
const fs = await Promise.resolve().then(() => __importStar(require('fs-extra')));
const path = await Promise.resolve().then(() => __importStar(require('path')));
// Remove any cache or config files
const configPaths = [
path.join(projectPath, '.context-forge'),
path.join(projectPath, 'node_modules/.cache'),
];
for (const configPath of configPaths) {
if (await fs.pathExists(configPath)) {
await fs.remove(configPath);
}
}
return true;
}
catch {
return false;
}
}
getPriorityColor(priority) {
switch (priority) {
case 'critical':
return 'red';
case 'high':
return 'yellow';
case 'medium':
return 'blue';
case 'low':
return 'gray';
default:
return 'white';
}
}
showAdditionalHelp(_error, _context) {
console.log(chalk_1.default.blue('š” Additional resources:'));
console.log(chalk_1.default.gray('⢠Documentation: https://github.com/webdevtodayjason/context-forge#readme'));
console.log(chalk_1.default.gray('⢠Issues: https://github.com/webdevtodayjason/context-forge/issues'));
console.log(chalk_1.default.gray('⢠Discord: Contact for community support'));
if (this.aiService.isAIEnabled()) {
console.log(chalk_1.default.gray('⢠AI assistance is available for more detailed suggestions'));
}
else {
console.log(chalk_1.default.gray('⢠Set ANTHROPIC_API_KEY for AI-powered error recovery'));
}
console.log('');
}
// Method to wrap command execution with error recovery
async executeWithRecovery(operation, context) {
try {
return await operation();
}
catch (error) {
await this.handleError(error, context);
throw error; // Re-throw after handling
}
}
}
exports.ErrorRecoveryService = ErrorRecoveryService;
//# sourceMappingURL=errorRecoveryService.js.map