import type { Logger, ScriptConfig } from '@polka-codes/core';
import type { ExecutionContext } from '../runWorkflow';
/**
 * Error thrown when script validation fails
 */
export declare const ScriptValidationError: new (args_0: string) => import("@polka-codes/core").BaseError;
/**
 * Error thrown when script execution times out
 */
export declare const ScriptTimeoutError: new (args_0: string, args_1: number) => import("@polka-codes/core").BaseError;
/**
 * Error thrown when script execution fails
 */
export declare const ScriptExecutionError: new (...args: any[]) => import("@polka-codes/core").BaseError;
/**
 * Options for script execution
 */
export interface ScriptRunnerOptions {
    /**
     * Path to the TypeScript script file
     */
    scriptPath: string;
    /**
     * Command-line arguments to pass to the script
     */
    args: string[];
    /**
     * Execution context (for CLI options, etc.)
     */
    context: Partial<ExecutionContext> & {
        projectRoot?: string;
    };
    /**
     * Logger instance for output
     */
    logger: Logger;
    /**
     * Execution timeout in milliseconds (default: 5 minutes)
     */
    timeout?: number;
}
/**
 * Result of script execution
 */
export interface ScriptExecutionResult {
    /**
     * Whether the script executed successfully
     */
    success: boolean;
    /**
     * Return value from the script (if any)
     */
    returnValue?: unknown;
    /**
     * Error if execution failed
     */
    error?: Error;
}
/**
 * Script context passed to main function
 * Provides scripts with access to logger, config, and project info
 */
export interface ScriptContext {
    /**
     * Logger instance for output
     */
    logger: Logger;
    /**
     * Project root directory
     */
    projectRoot: string;
    /**
     * Additional context from execution environment
     */
    [key: string]: unknown;
}
/**
 * Validates that a script path is safe to execute
 *
 * @param scriptPath - Path to the script file
 * @param projectRoot - Root directory of the project (defaults to cwd)
 * @throws {ScriptValidationError} if validation fails
 */
export declare function validateScriptPath(scriptPath: string, projectRoot?: string): void;
/**
 * Validates script permissions based on security configuration
 *
 * IMPORTANT: TypeScript scripts currently run with full process permissions.
 * Permission declarations in the config are ADVISORY ONLY for future sandboxing.
 * Scripts can access filesystem, network, and subprocesses regardless of declared permissions.
 *
 * @param script - Script configuration
 * @throws {ScriptValidationError} if permissions are invalid
 */
export declare function validateScriptPermissions(script: ScriptConfig, logger?: {
    warn: (message: string) => void;
}): void;
/**
 * In-process script runner for TypeScript files
 *
 * Executes TypeScript scripts by dynamically importing them as modules.
 * Scripts should export a `main(args: string[], context: ScriptContext)` function.
 *
 * **Important Limitations:**
 *
 * 1. **Synchronous Blocking**: The timeout mechanism uses `Promise.race()` which only
 *    handles timeouts for asynchronous operations. If a script performs a synchronous
 *    blocking operation (e.g., `while(true) {}`), the timeout will not trigger and the
 *    process will hang indefinitely. This is a known limitation of in-process script
 *    execution without using Worker threads or child processes.
 *
 * 2. **Path Resolution**: Script paths are resolved relative to `process.cwd()`. If the
 *    CLI is run from a subdirectory, script paths from config may not resolve correctly.
 *    The caller should ensure paths are absolute or relative to the correct working directory.
 *
 * 3. **Memory Leak Warning**: Cache busting via timestamp query parameters (`?t=...`)
 *    only invalidates the entry point script. If a script imports other local modules,
 *    those dependencies remain cached across executions. This is acceptable for CLI
 *    commands that run once and exit, but **will cause memory leaks in long-running
 *    processes**. Do NOT use this ScriptRunner in the `packages/runner` service or
 *    other long-lived contexts without implementing proper module cache clearing
 *    strategies (e.g., using a custom VM context or Worker threads).
 *
 * @example
 * ```typescript
 * // Script file (scripts/deploy.ts):
 * export async function main(args: string[], context: ScriptContext) {
 *   const { logger, projectRoot } = context
 *   logger.info('Deploying...')
 *   // Use logger and projectRoot as needed
 * }
 *
 * // Execution:
 * const runner = new ScriptRunner()
 * const result = await runner.execute({
 *   scriptPath: './scripts/deploy.ts',
 *   args: ['--production'],
 *   context: { projectRoot: '/path/to/project' },
 *   logger: createLogger({ verbose: 1 }),
 *   timeout: 60000
 * })
 * ```
 */
export declare class ScriptRunner {
    /**
     * Execute a TypeScript script
     *
     * @param options - Script execution options
     * @returns Promise<ScriptExecutionResult>
     * @throws {ScriptValidationError} if validation fails
     * @throws {ScriptTimeoutError} if execution times out
     * @throws {ScriptExecutionError} if execution fails
     */
    execute(options: ScriptRunnerOptions): Promise<ScriptExecutionResult>;
    /**
     * Execute a function with a timeout
     *
     * @param ms - Timeout in milliseconds
     * @param fn - Function to execute
     * @returns Promise<T>
     * @throws {ScriptTimeoutError} if timeout is exceeded
     */
    private withTimeout;
    /**
     * Check if a script is a TypeScript file
     */
    isTypeScriptScript(script: ScriptConfig): script is {
        script: string;
    };
    /**
     * Check if a script is a workflow YAML
     */
    isWorkflowScript(script: ScriptConfig): script is {
        workflow: string;
    };
    /**
     * Check if a script is a shell command
     */
    isShellCommand(script: ScriptConfig): script is string | {
        command: string;
        description: string;
    };
}
//# sourceMappingURL=runner.d.ts.map