// engine/plugin-installer/error-classifier.ts — SPEC-605
// Classifies plugin install errors into actionable categories.
const ERROR_PATTERNS = [
    {
        type: 'network',
        pattern: /ETIMEDOUT|ECONNREFUSED|ECONNRESET|ENOTFOUND|fetch failed/i,
        recovery: 'Check your network connection and retry. If behind a proxy, configure HTTPS_PROXY.',
    },
    {
        type: 'permission',
        pattern: /EACCES|EPERM|permission denied/i,
        recovery: 'Run the command with appropriate permissions or fix directory ownership with `chown`.',
    },
    {
        type: 'compatibility',
        pattern: /version|incompatible|requires|semver/i,
        recovery: 'Update your Claude CLI or the plugin to compatible versions. Check the plugin documentation.',
    },
    {
        type: 'not-found',
        pattern: /not found|404|no such plugin/i,
        recovery: 'Verify the plugin ID is correct. Search the marketplace: `claude plugin search`.',
    },
];
const UNKNOWN_RECOVERY = 'Check the error message above and consult the plugin documentation or support.';
/**
 * Classify a plugin install error message into a typed PluginInstallError
 * with an actionable recovery suggestion.
 */
export function classifyInstallError(pluginId, errorMessage) {
    for (const { type, pattern, recovery } of ERROR_PATTERNS) {
        if (pattern.test(errorMessage)) {
            return { pluginId, errorType: type, message: errorMessage, recovery };
        }
    }
    return {
        pluginId,
        errorType: 'unknown',
        message: errorMessage,
        recovery: UNKNOWN_RECOVERY,
    };
}
//# sourceMappingURL=error-classifier.js.map