/** * Swarm Task Runner * * Orchestrates automated execution of Swarm tasks by: * - Polling for pending tasks and executing them on agent processes * - Managing task dependencies (depends_on) and file conflict detection * - Handling both event-driven (immediate) and polling-based execution * - Automatically stopping sessions when complete * * Features: * - Dependency resolution: tasks wait for prerequisite tasks to complete * - File conflict warnings: detects when multiple tasks modify same files * - Stale lease expiration: recovers from agent crashes * - Event emission: task-completed, task-failed, session-complete, file-conflict * * @module swarm-task-runner * @version 1.0 */ import { EventEmitter } from 'events'; import { SwarmManager } from './swarm-manager.js'; import { AgentProcessManager } from '../agent-process-manager.js'; import type { ContextInjector } from '../../gateways/context-injector.js'; import type { SwarmAntiPatternDetector } from './swarm-anti-pattern-detector.js'; /** * Result of executing a single task */ export interface TaskExecutionResult { taskId: string; agentId: string; status: 'completed' | 'failed' | 'deferred' | 'retrying'; result?: string; error?: string; warnings?: string[]; retryCount?: number; } /** * Swarm Task Runner * * Manages automated execution of swarm tasks across multiple agent processes. * Supports both event-driven (immediate) and polling-based execution modes. * * Events: * - 'task-completed': (result: TaskExecutionResult) => void * - 'task-failed': (result: TaskExecutionResult) => void * - 'session-complete': (sessionId: string) => void * - 'file-conflict': (taskId: string, conflictingFiles: string[], conflictingTasks: string[]) => void */ export declare class SwarmTaskRunner extends EventEmitter { private swarmManager; private agentProcessManager; private sessions; private pollingIntervalMs; private contextInjector?; private pollingSessionIds; private enableAutoCheckpoint; private checkpointDebounceMs; private checkpointFailCounts; private checkpointTimers; private antiPatternDetector?; private maxRetries; constructor(swarmManager: SwarmManager, agentProcessManager: AgentProcessManager, options?: { pollingIntervalMs?: number; contextInjector?: ContextInjector; antiPatternDetector?: SwarmAntiPatternDetector; maxRetries?: number; enableAutoCheckpoint?: boolean; checkpointDebounceMs?: number; }); /** * Start a session with automatic polling * * @param sessionId - Session ID to start */ startSession(sessionId: string): void; /** * Stop a session * * @param sessionId - Session ID to stop */ stopSession(sessionId: string): void; /** * Execute a specific task immediately (event-driven mode) * * Used for mention-triggered tasks that should run immediately * rather than waiting for the next polling cycle. * * @param sessionId - Session ID * @param taskId - Task ID to execute * @param source - Source platform (e.g., 'discord', 'slack') * @param channelId - Channel ID * @returns Execution result */ executeImmediateTask(sessionId: string, taskId: string, source: string, channelId: string): Promise; /** * Poll for pending tasks and execute them * * @param sessionId - Session ID to poll */ private pollAndExecute; /** * Internal poll logic (extracted for concurrency guard) */ private pollAndExecuteInternal; /** * Execute a single task * * @param task - Task to execute * @param source - Source platform * @param channelId - Channel ID * @returns TaskExecutionResult with status and optional error */ private executeTask; /** * Check if all task dependencies are met * * @param db - Database instance * @param task - Task to check (avoids redundant SELECT) * @returns true if all dependencies are completed, false if pending/failed/missing */ private checkDependencies; /** * Check for file conflicts with other claimed tasks * * @param db - Database instance * @param sessionId - Session ID * @param task - Task to check * @returns Array of conflicting tasks (empty if no conflicts) */ private checkFileConflicts; /** * Setup auto-checkpoint listeners (F6) */ private setupAutoCheckpoint; /** * Schedule a debounced checkpoint save (F6) */ private scheduleCheckpoint; /** * Save session checkpoint to MAMA (F6) */ private saveSessionCheckpoint; /** * Stop all sessions */ stopAll(): void; /** * Get active session count */ getActiveSessionCount(): number; /** * Get active session IDs */ getActiveSessionIds(): string[]; } //# sourceMappingURL=swarm-task-runner.d.ts.map