/**
 * Plugin Executor Service
 *
 * This service executes plugins for stewards. Plugins enable custom automated
 * maintenance tasks via playbooks, scripts, or commands.
 *
 * TB-O23a: Plugin System for Stewards
 *
 * @module
 */
import type { PlaybookId, Timestamp } from '@stoneforge/core';
import type { QuarryAPI } from '@stoneforge/quarry';
/**
 * Plugin type discriminator
 */
export type PluginType = 'playbook' | 'script' | 'command';
/**
 * All valid plugin type values
 */
export declare const PluginTypeValues: readonly ["playbook", "script", "command"];
/**
 * Type guard for plugin type
 */
export declare function isPluginType(value: unknown): value is PluginType;
/**
 * Base plugin configuration shared by all plugin types
 */
interface BasePlugin {
    /** Unique name for this plugin within the steward */
    readonly name: string;
    /** Optional description of what this plugin does */
    readonly description?: string;
    /** Execution timeout in milliseconds (default: 5 minutes) */
    readonly timeout?: number;
    /** Whether to run this plugin on steward startup (default: false) */
    readonly runOnStartup?: boolean;
    /** Whether to continue executing subsequent plugins if this one fails (default: true) */
    readonly continueOnError?: boolean;
    /** Optional tags for categorizing plugins */
    readonly tags?: readonly string[];
}
/**
 * Plugin that executes a playbook
 */
export interface PlaybookPlugin extends BasePlugin {
    readonly type: 'playbook';
    /** The playbook ID to execute */
    readonly playbookId: PlaybookId;
    /** Variables to pass to the playbook */
    readonly variables?: Record<string, string>;
}
/**
 * Plugin that executes a script file
 */
export interface ScriptPlugin extends BasePlugin {
    readonly type: 'script';
    /** Path to the script (relative to workspace root or absolute) */
    readonly path: string;
    /** Arguments to pass to the script */
    readonly args?: readonly string[];
    /** Environment variables to set */
    readonly env?: Record<string, string>;
    /** Working directory (default: workspace root) */
    readonly cwd?: string;
}
/**
 * Plugin that executes a CLI command
 */
export interface CommandPlugin extends BasePlugin {
    readonly type: 'command';
    /** The command to execute (passed to shell) */
    readonly command: string;
    /** Working directory (default: workspace root) */
    readonly cwd?: string;
    /** Environment variables to set */
    readonly env?: Record<string, string>;
}
/**
 * Union type for all plugin configurations
 */
export type StewardPlugin = PlaybookPlugin | ScriptPlugin | CommandPlugin;
/**
 * Type guard for PlaybookPlugin
 */
export declare function isPlaybookPlugin(plugin: StewardPlugin): plugin is PlaybookPlugin;
/**
 * Type guard for ScriptPlugin
 */
export declare function isScriptPlugin(plugin: StewardPlugin): plugin is ScriptPlugin;
/**
 * Type guard for CommandPlugin
 */
export declare function isCommandPlugin(plugin: StewardPlugin): plugin is CommandPlugin;
/**
 * Validates that a value is a valid StewardPlugin
 */
export declare function isValidPlugin(value: unknown): value is StewardPlugin;
/**
 * Result of executing a single plugin
 */
export interface PluginExecutionResult {
    /** Plugin name */
    readonly pluginName: string;
    /** Plugin type */
    readonly pluginType: PluginType;
    /** Whether execution succeeded */
    readonly success: boolean;
    /** Error message if failed */
    readonly error?: string;
    /** Standard output from execution */
    readonly stdout?: string;
    /** Standard error from execution */
    readonly stderr?: string;
    /** Exit code (for script/command plugins) */
    readonly exitCode?: number;
    /** Duration of execution in milliseconds */
    readonly durationMs: number;
    /** Items processed (if applicable) */
    readonly itemsProcessed?: number;
    /** Timestamp when execution started */
    readonly startedAt: Timestamp;
    /** Timestamp when execution completed */
    readonly completedAt: Timestamp;
}
/**
 * Result of executing multiple plugins
 */
export interface BatchPluginExecutionResult {
    /** Total number of plugins */
    readonly total: number;
    /** Number of successful executions */
    readonly succeeded: number;
    /** Number of failed executions */
    readonly failed: number;
    /** Number of skipped executions */
    readonly skipped: number;
    /** Individual plugin results */
    readonly results: readonly PluginExecutionResult[];
    /** Total duration in milliseconds */
    readonly durationMs: number;
    /** Whether all plugins succeeded */
    readonly allSucceeded: boolean;
}
/**
 * Options for executing plugins
 */
export interface PluginExecutionOptions {
    /** Working directory for script/command plugins */
    readonly workspaceRoot?: string;
    /** Default timeout in milliseconds (default: 5 minutes) */
    readonly defaultTimeout?: number;
    /** Additional environment variables */
    readonly env?: Record<string, string>;
    /** Context data passed to playbook plugins */
    readonly context?: Record<string, unknown>;
    /** Whether to stop on first error (default: false) */
    readonly stopOnError?: boolean;
}
/**
 * Built-in plugin: Garbage collect ephemeral workflows
 */
export declare const GcEphemeralTasksPlugin: CommandPlugin;
/**
 * Built-in plugin: Cleanup stale worktrees
 */
export declare const CleanupStaleWorktreesPlugin: CommandPlugin;
/**
 * Built-in plugin: Garbage collect ephemeral workflows
 */
export declare const GcEphemeralWorkflowsPlugin: CommandPlugin;
/**
 * Built-in plugin: Health check agents
 * This is a placeholder - actual implementation would query agent statuses
 */
export declare const HealthCheckAgentsPlugin: CommandPlugin;
/**
 * All built-in plugins
 */
export declare const BuiltInPlugins: Record<string, StewardPlugin>;
/**
 * Get a built-in plugin by name
 */
export declare function getBuiltInPlugin(name: string): StewardPlugin | undefined;
/**
 * List all built-in plugin names
 */
export declare function listBuiltInPlugins(): string[];
/**
 * Plugin Executor service interface
 */
export interface PluginExecutor {
    /**
     * Executes a single plugin
     */
    execute(plugin: StewardPlugin, options?: PluginExecutionOptions): Promise<PluginExecutionResult>;
    /**
     * Executes multiple plugins in sequence
     */
    executeBatch(plugins: readonly StewardPlugin[], options?: PluginExecutionOptions): Promise<BatchPluginExecutionResult>;
    /**
     * Validates a plugin configuration
     */
    validate(plugin: StewardPlugin): {
        valid: boolean;
        errors: string[];
    };
    /**
     * Gets a built-in plugin by name
     */
    getBuiltIn(name: string): StewardPlugin | undefined;
    /**
     * Lists all built-in plugins
     */
    listBuiltIns(): string[];
}
/**
 * Implementation of the Plugin Executor service
 */
export declare class PluginExecutorImpl implements PluginExecutor {
    private readonly api?;
    private readonly defaultWorkspaceRoot;
    constructor(options?: {
        api?: QuarryAPI;
        workspaceRoot?: string;
    });
    execute(plugin: StewardPlugin, options?: PluginExecutionOptions): Promise<PluginExecutionResult>;
    executeBatch(plugins: readonly StewardPlugin[], options?: PluginExecutionOptions): Promise<BatchPluginExecutionResult>;
    validate(plugin: StewardPlugin): {
        valid: boolean;
        errors: string[];
    };
    getBuiltIn(name: string): StewardPlugin | undefined;
    listBuiltIns(): string[];
    private executePlaybook;
    private executeScript;
    private executeCommand;
    private runShellCommand;
}
/**
 * Creates a PluginExecutor instance
 */
export declare function createPluginExecutor(options?: {
    api?: QuarryAPI;
    workspaceRoot?: string;
}): PluginExecutor;
export {};
//# sourceMappingURL=plugin-executor.d.ts.map