vibe-coder-mcp
Version:
Production-ready MCP server with complete agent integration, multi-transport support, and comprehensive development automation tools for AI-assisted workflows.
351 lines (350 loc) • 12.6 kB
JavaScript
export class ContextCuratorError extends Error {
context;
recoverable;
severity;
operation;
timestamp;
cause;
constructor(message, options = {}) {
super(message);
this.name = 'ContextCuratorError';
this.context = options.context;
this.recoverable = options.recoverable ?? false;
this.severity = options.severity ?? 'medium';
this.operation = options.operation;
this.timestamp = new Date();
this.cause = options.cause;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
getRecoveryHints() {
const hints = [];
if (this.recoverable) {
hints.push('This error may be recoverable - consider retrying the operation');
if (this.operation) {
hints.push(`Check the ${this.operation} operation parameters and configuration`);
}
if (this.context?.filePath) {
hints.push(`Verify file accessibility: ${this.context.filePath}`);
}
if (this.context?.tokenBudget) {
hints.push('Consider adjusting token budget or file selection criteria');
}
}
else {
hints.push('This error requires manual intervention to resolve');
}
return hints;
}
toStructured() {
return {
name: this.name,
message: this.message,
severity: this.severity,
recoverable: this.recoverable,
operation: this.operation,
timestamp: this.timestamp.toISOString(),
context: this.context,
stack: this.stack,
cause: this.cause ? {
name: this.cause.name,
message: this.cause.message,
stack: this.cause.stack
} : undefined
};
}
}
export class ContextCuratorLLMError extends ContextCuratorError {
task;
model;
tokenCount;
constructor(message, context) {
super(message, {
context,
recoverable: true,
severity: 'medium',
operation: 'llm_processing',
cause: context.cause
});
this.name = 'ContextCuratorLLMError';
this.task = context.task;
this.model = context.model;
this.tokenCount = context.tokenCount;
}
getRecoveryHints() {
const hints = super.getRecoveryHints();
hints.push(`Retry the ${this.task} operation with adjusted parameters`);
if (this.tokenCount && this.tokenCount > 100000) {
hints.push('Consider reducing token count by optimizing file content or selection');
}
if (this.model) {
hints.push(`Consider using a different model than ${this.model}`);
}
hints.push('Check LLM service availability and rate limits');
return hints;
}
}
export class ContextCuratorConfigError extends ContextCuratorError {
configKey;
expectedType;
constructor(message, context) {
super(message, {
context,
recoverable: false,
severity: 'high',
operation: 'configuration_loading'
});
this.name = 'ContextCuratorConfigError';
this.configKey = context?.configKey;
this.expectedType = context?.expectedType;
}
getRecoveryHints() {
const hints = super.getRecoveryHints();
if (this.configKey) {
hints.push(`Check configuration for key: ${this.configKey}`);
if (this.expectedType) {
hints.push(`Ensure ${this.configKey} is of type: ${this.expectedType}`);
}
}
hints.push('Verify environment variables and configuration files');
hints.push('Check Context Curator configuration documentation');
return hints;
}
}
export class ContextCuratorFileError extends ContextCuratorError {
filePath;
fileOperation;
constructor(message, context) {
super(message, {
context,
recoverable: true,
severity: 'medium',
operation: 'file_processing',
cause: context.cause
});
this.name = 'ContextCuratorFileError';
this.filePath = context.filePath;
this.fileOperation = context.fileOperation;
}
getRecoveryHints() {
const hints = super.getRecoveryHints();
hints.push(`Verify file exists and is accessible: ${this.filePath}`);
hints.push(`Check permissions for ${this.fileOperation} operation`);
if (this.fileOperation === 'read') {
hints.push('Ensure file is not locked by another process');
hints.push('Check file encoding and format');
}
if (this.fileOperation === 'glob') {
hints.push('Verify glob pattern syntax and directory structure');
}
return hints;
}
}
export class ContextCuratorValidationError extends ContextCuratorError {
validationIssues;
schemaName;
constructor(message, context) {
super(message, {
context: { ...context, validationIssues: context?.validationIssues },
recoverable: true,
severity: 'medium',
operation: 'data_validation'
});
this.name = 'ContextCuratorValidationError';
this.validationIssues = context?.validationIssues;
this.schemaName = context?.schemaName;
}
getRecoveryHints() {
const hints = super.getRecoveryHints();
if (this.schemaName) {
hints.push(`Check data format for schema: ${this.schemaName}`);
}
if (this.validationIssues && this.validationIssues.length > 0) {
hints.push('Validation issues found:');
this.validationIssues.forEach(issue => {
hints.push(` - ${issue.path.join('.')}: ${issue.message}`);
});
}
hints.push('Verify input data matches expected schema format');
return hints;
}
}
export class ContextCuratorTokenBudgetError extends ContextCuratorError {
currentTokens;
maxTokens;
overagePercentage;
constructor(message, context) {
const overagePercentage = ((context.currentTokens - context.maxTokens) / context.maxTokens) * 100;
super(message, {
context: { ...context, overagePercentage },
recoverable: true,
severity: overagePercentage > 50 ? 'high' : 'medium',
operation: context.operation || 'token_estimation'
});
this.name = 'ContextCuratorTokenBudgetError';
this.currentTokens = context.currentTokens;
this.maxTokens = context.maxTokens;
this.overagePercentage = overagePercentage;
}
getRecoveryHints() {
const hints = super.getRecoveryHints();
hints.push(`Current tokens (${this.currentTokens}) exceed budget (${this.maxTokens}) by ${this.overagePercentage.toFixed(1)}%`);
hints.push('Consider reducing file selection or optimizing content');
hints.push('Increase token budget if more content is essential');
hints.push('Use more aggressive content optimization settings');
if (this.overagePercentage > 100) {
hints.push('Consider splitting the task into smaller chunks');
}
return hints;
}
}
export class ContextCuratorTimeoutError extends ContextCuratorError {
timeoutMs;
actualDurationMs;
constructor(message, context) {
super(message, {
context,
recoverable: true,
severity: 'medium',
operation: context.operation || 'async_operation'
});
this.name = 'ContextCuratorTimeoutError';
this.timeoutMs = context.timeoutMs;
this.actualDurationMs = context.actualDurationMs;
}
getRecoveryHints() {
const hints = super.getRecoveryHints();
hints.push(`Operation timed out after ${this.timeoutMs}ms`);
hints.push('Consider increasing timeout duration');
hints.push('Check network connectivity and service availability');
hints.push('Retry the operation with exponential backoff');
if (this.actualDurationMs) {
hints.push(`Operation ran for ${this.actualDurationMs}ms before timeout`);
}
return hints;
}
}
export class ErrorHandler {
static async withErrorContext(operation, fn, context) {
try {
return await fn();
}
catch (error) {
if (error instanceof ContextCuratorError) {
throw new ContextCuratorError(error.message, {
...error,
context: { ...error.context, ...context },
operation: error.operation || operation
});
}
else {
throw new ContextCuratorError(error instanceof Error ? error.message : 'Unknown error occurred', {
context,
operation,
cause: error instanceof Error ? error : undefined
});
}
}
}
static isRecoverable(error) {
if (error instanceof ContextCuratorError) {
return error.recoverable;
}
return false;
}
static getSeverity(error) {
if (error instanceof ContextCuratorError) {
return error.severity;
}
return 'medium';
}
static formatForLogging(error) {
if (error instanceof ContextCuratorError) {
return error.toStructured();
}
else if (error instanceof Error) {
return {
name: error.name,
message: error.message,
stack: error.stack,
severity: 'medium',
recoverable: false
};
}
else {
return {
name: 'UnknownError',
message: String(error),
severity: 'medium',
recoverable: false
};
}
}
static validateFileOperation(operation) {
const validOperations = ['read', 'write', 'access', 'stat', 'glob'];
if (typeof operation === 'string' && validOperations.includes(operation)) {
return operation;
}
return 'read';
}
static createError(message, operation, cause, context) {
switch (operation) {
case 'llm_processing':
case 'intent_analysis':
case 'prompt_refinement':
return new ContextCuratorLLMError(message, {
task: operation,
cause,
...context
});
case 'configuration_loading':
case 'config_validation':
return new ContextCuratorConfigError(message, {
cause,
...context
});
case 'file_processing':
case 'file_reading':
case 'file_discovery':
return new ContextCuratorFileError(message, {
filePath: context?.filePath || 'unknown',
fileOperation: this.validateFileOperation(context?.fileOperation),
cause,
...context
});
case 'data_validation':
case 'schema_validation':
return new ContextCuratorValidationError(message, {
cause,
...context
});
case 'token_estimation':
case 'token_budget':
if (context?.currentTokens && context?.maxTokens) {
return new ContextCuratorTokenBudgetError(message, {
currentTokens: context.currentTokens,
maxTokens: context.maxTokens,
operation,
...context
});
}
break;
case 'timeout':
case 'async_operation':
if (context?.timeoutMs) {
return new ContextCuratorTimeoutError(message, {
timeoutMs: context.timeoutMs,
operation,
...context
});
}
break;
}
return new ContextCuratorError(message, {
context,
operation,
cause
});
}
}