/**
 * Plugin Marketplace System
 *
 * Features:
 * - Plugin discovery and search
 * - Installation and updates
 * - Plugin lifecycle management
 * - Sandboxed execution
 * - Version compatibility checking
 * - Plugin ratings and reviews
 *
 * Allows extending Code Buddy with community plugins.
 */
import { EventEmitter } from 'events';
import { PluginSandbox } from './sandbox-worker.js';
export interface Plugin {
    id: string;
    name: string;
    description: string;
    version: string;
    author: Author;
    license: string;
    repository?: string;
    homepage?: string;
    keywords: string[];
    category: PluginCategory;
    engines: {
        grok: string;
        node?: string;
    };
    main: string;
    dependencies?: Record<string, string>;
    permissions: Permission[];
    config?: PluginConfigSchema;
    readme?: string;
    changelog?: string;
    icon?: string;
}
export interface Author {
    name: string;
    email?: string;
    url?: string;
}
export type PluginCategory = 'tools' | 'providers' | 'themes' | 'languages' | 'integrations' | 'utilities' | 'ai' | 'productivity';
export interface Permission {
    type: 'filesystem' | 'network' | 'shell' | 'env' | 'api' | 'system';
    scope?: string;
    reason: string;
}
export interface PluginConfigSchema {
    type: 'object';
    properties: Record<string, {
        type: string;
        description: string;
        default?: unknown;
        required?: boolean;
    }>;
}
export interface InstalledPlugin extends Plugin {
    installedAt: Date;
    updatedAt: Date;
    enabled: boolean;
    configValues: Record<string, unknown>;
    installPath: string;
}
export interface PluginSearchResult {
    id: string;
    name: string;
    description: string;
    version: string;
    author: string;
    downloads: number;
    rating: number;
    category: PluginCategory;
    verified: boolean;
    featured: boolean;
}
export interface PluginReview {
    id: string;
    pluginId: string;
    userId: string;
    userName: string;
    rating: number;
    title: string;
    content: string;
    createdAt: Date;
    helpful: number;
}
export interface PluginInstance {
    plugin: InstalledPlugin;
    module: unknown;
    api: PluginAPI;
    sandbox?: PluginSandbox;
}
export interface PluginAPI {
    registerCommand: (name: string, handler: CommandHandler) => void;
    registerTool: (name: string, tool: ToolDefinition) => void;
    registerProvider: (name: string, provider: ProviderDefinition) => void;
    registerHook: (event: string, handler: HookHandler) => void;
    getConfig: () => Record<string, unknown>;
    setConfig: (key: string, value: unknown) => void;
    log: (level: string, message: string) => void;
    storage: {
        get: (key: string) => Promise<unknown>;
        set: (key: string, value: unknown) => Promise<void>;
        delete: (key: string) => Promise<void>;
    };
}
export interface CommandContext {
    cwd: string;
    env?: Record<string, string>;
    [key: string]: unknown;
}
export type CommandHandler = (args: string[], context: CommandContext) => Promise<string | void>;
export type HookHandler = (data: unknown) => Promise<unknown>;
export interface ToolDefinition {
    description: string;
    parameters: Record<string, unknown>;
    execute: (params: Record<string, unknown>) => Promise<unknown>;
}
export interface ProviderDefinition {
    type: 'llm' | 'embedding' | 'tts' | 'stt';
    models?: string[];
    execute: (request: Record<string, unknown>) => Promise<unknown>;
}
export interface MarketplaceConfig {
    registryUrl: string;
    autoUpdate: boolean;
    checkUpdatesInterval: number;
    allowUntrusted: boolean;
    sandboxPlugins: boolean;
    maxPlugins: number;
}
/**
 * Plugin Marketplace
 */
export declare class PluginMarketplace extends EventEmitter {
    private config;
    private pluginsDir;
    private installedPlugins;
    private loadedPlugins;
    private commands;
    private tools;
    private providers;
    private hooks;
    private updateCheckerIntervalId;
    constructor(config?: Partial<MarketplaceConfig>);
    /**
     * Initialize marketplace
     */
    private initialize;
    /**
     * Load installed plugins from disk
     */
    private loadInstalledPlugins;
    /**
     * Save installed plugins manifest
     */
    private saveManifest;
    /**
     * Search plugins in marketplace
     */
    search(query: string, options?: {
        category?: PluginCategory;
        limit?: number;
        offset?: number;
        sort?: 'downloads' | 'rating' | 'updated' | 'name';
    }): Promise<PluginSearchResult[]>;
    /**
     * Get plugin details
     */
    getPluginDetails(pluginId: string): Promise<Plugin | null>;
    /**
     * Install a plugin
     */
    install(pluginId: string, version?: string): Promise<InstalledPlugin | null>;
    /**
     * Extract plugin archive
     */
    private extractPlugin;
    /**
     * Uninstall a plugin
     */
    uninstall(pluginId: string): Promise<void>;
    /**
     * Update a plugin
     */
    update(pluginId: string): Promise<InstalledPlugin | null>;
    /**
     * Check for updates
     */
    checkUpdates(): Promise<Array<{
        plugin: InstalledPlugin;
        latestVersion: string;
    }>>;
    /**
     * Start update checker
     */
    private startUpdateChecker;
    /**
     * Validate plugin path is within allowed directory
     */
    private validatePluginPath;
    /**
     * Load a plugin
     */
    loadPlugin(pluginId: string): Promise<void>;
    /**
     * Unload a plugin
     */
    unloadPlugin(pluginId: string): Promise<void>;
    /**
     * Remove plugin registrations
     */
    private removePluginRegistrations;
    /**
     * Create plugin API
     */
    private createPluginAPI;
    /**
     * Execute a plugin command
     */
    executeCommand(name: string, args: string[], context: CommandContext): Promise<string | void>;
    /**
     * Execute a plugin tool
     */
    executeTool(name: string, params: Record<string, unknown>): Promise<unknown>;
    /**
     * Execute hooks
     */
    executeHooks(event: string, data: unknown): Promise<unknown>;
    /**
     * Check version compatibility
     */
    private isCompatible;
    /**
     * Get default config values
     */
    private getDefaultConfig;
    /**
     * Enable a plugin
     */
    enable(pluginId: string): Promise<void>;
    /**
     * Disable a plugin
     */
    disable(pluginId: string): Promise<void>;
    /**
     * Get installed plugins
     */
    getInstalled(): InstalledPlugin[];
    /**
     * Get loaded plugins
     */
    getLoaded(): string[];
    /**
     * Get registered commands
     */
    getCommands(): string[];
    /**
     * Get registered tools
     */
    getTools(): string[];
    /**
     * Get tool definition by name
     */
    getToolDefinition(name: string): ToolDefinition | undefined;
    /**
     * Format marketplace status
     */
    formatStatus(): string;
    /**
     * Dispose
     */
    dispose(): Promise<void>;
}
export declare function getPluginMarketplace(config?: Partial<MarketplaceConfig>): PluginMarketplace;
export declare function resetPluginMarketplace(): void;
