/** * Simple Execution Engine * * Queue-based execution engine that spawns a process per task * with concurrency limits. Implements the "simple first" approach. * * @module execution/engine/simple-engine */ import type { IExecutionEngine } from "./engine.js"; import type { ExecutionTask, ExecutionResult, TaskStatus, EngineMetrics, TaskCompleteHandler, TaskFailedHandler, EngineConfig } from "./types.js"; import type { IProcessManager } from "../process/manager.js"; /** * SimpleExecutionEngine - Queue-based task execution with concurrency control * * Key features: * - FIFO queue for task ordering * - Configurable concurrency limit (default: 3) * - Automatic retry on failure * - Event emission for task lifecycle * - Promise-based waiting * - Graceful shutdown */ export declare class SimpleExecutionEngine implements IExecutionEngine { private _processManager; private _config; private taskQueue; private runningTasks; private completedResults; private taskResolvers; private metrics; private completeHandlers; private failedHandlers; private pollingIntervals; /** * Create a new SimpleExecutionEngine * * @param processManager - Process manager for spawning processes * @param config - Engine configuration (required, must include defaultProcessConfig) * * @example * ```typescript * const adapter = new ClaudeCodeAdapter(); * const processConfig = adapter.buildProcessConfig({ * workDir: '/path/to/project', * print: true, * outputFormat: 'stream-json', * }); * * const engine = new SimpleExecutionEngine(processManager, { * maxConcurrent: 3, * defaultProcessConfig: processConfig, * }); * ``` */ constructor(_processManager: IProcessManager, _config?: EngineConfig); /** * Submit a single task for execution * * Adds task to queue and attempts to start execution if capacity available. * * @param task - The task to execute * @returns Promise resolving to the task ID */ submitTask(task: ExecutionTask): Promise; /** * Submit multiple tasks for execution * * @param tasks - Array of tasks to execute * @returns Promise resolving to array of task IDs */ submitTasks(tasks: ExecutionTask[]): Promise; /** * Process the task queue * * Dequeues tasks and starts execution while capacity is available. * Checks dependencies before execution and re-queues if not met. * * @private */ private processQueue; /** * Check if all task dependencies are met * * @param task - Task to check * @returns True if all dependencies completed successfully * @private */ private areDependenciesMet; /** * Check if any task dependency has failed * * @param task - Task to check * @returns True if any dependency failed * @private */ private hasFailedDependency; /** * Track task as running and update capacity metrics * * @param task - Task to start tracking * @private */ private trackTaskStart; /** * Track task completion and release capacity * * @param taskId - ID of completed task * @private */ private trackTaskComplete; /** * Execute a task * * Acquires a process, sends the prompt, collects output, and builds the result. * * @param task - Task to execute * @private */ private executeTask; /** * Wait for a process to exit * * @param process - The managed process to wait for * @param timeoutMs - Optional timeout in milliseconds * @private */ private waitForProcessExit; /** * Parse metadata from stream-json output * * Extracts tools used, files changed, tokens, etc. from the output. * * @param output - Raw output from Claude Code * @returns Parsed metadata * @private */ private parseMetadata; /** * Handle task failure * * Implements automatic retry logic if maxRetries is configured. * Re-queues failed tasks at front of queue for priority retry. * * @param taskId - ID of failed task * @param error - Error that occurred * @private */ private handleTaskFailure; /** * Cancel a queued or running task * * Removes task from queue if still queued, or terminates process if running. * Idempotent - safe to call multiple times or for non-existent tasks. * * @param taskId - ID of task to cancel */ cancelTask(taskId: string): Promise; /** * Get current status of a task */ getTaskStatus(taskId: string): TaskStatus | null; /** * Wait for a task to complete * * Returns a promise that resolves with the task result when complete. * Supports multiple concurrent waiters for the same task. * * @param taskId - ID of the task to wait for * @returns Promise resolving to the execution result */ waitForTask(taskId: string): Promise; /** * Wait for multiple tasks to complete * * Returns a promise that resolves when all tasks complete. * * @param taskIds - Array of task IDs to wait for * @returns Promise resolving to array of execution results */ waitForTasks(taskIds: string[]): Promise; /** * Get current engine metrics * * Returns defensive copy of current metrics. * * @returns Current engine metrics */ getMetrics(): EngineMetrics; /** * Register handler for task completion events */ onTaskComplete(handler: TaskCompleteHandler): void; /** * Register handler for task failure events */ onTaskFailed(handler: TaskFailedHandler): void; /** * Gracefully shutdown the engine * * Cancels all running tasks, clears the queue, and shuts down the process manager. * Idempotent - safe to call multiple times. */ shutdown(): Promise; } //# sourceMappingURL=simple-engine.d.ts.map