/** * Task Coordinator * * Bridges AgentRouter execution with Claude Code Tasks. * Since MCP tools cannot directly invoke Claude Code tools, * the coordinator returns INSTRUCTIONS for Claude to execute. * * Enhanced with worktree allocation support for coding agents * that need isolated git workspaces for file modifications. */ import type { Logger } from "../observability/logger.js"; import type { ConfigManager } from "../config/manager.js"; import type { StateCoordinator, DeleteTaskOptions } from "./state-coordinator.js"; import type { WorktreeManager } from "../worktrees/manager.js"; import type { AgentResponse, ClaimInstructions, CompletionResult, FailureResult, TaskExecution, WorktreeConfig, Worktree, WorktreeInstructions } from "../types.js"; /** * Options for TaskCoordinator construction */ export interface TaskCoordinatorOptions { /** Logger instance */ logger: Logger; /** Optional StateCoordinator for unified state management */ stateCoordinator?: StateCoordinator; /** Optional WorktreeManager for worktree allocation */ worktreeManager?: WorktreeManager; /** Optional ConfigManager to check role configurations */ configManager?: ConfigManager; /** Optional worktree config to check if worktrees are enabled */ worktreeConfig?: WorktreeConfig; } /** * Result of starting an execution with optional worktree allocation */ export interface ExecutionStartResult { /** The task execution record */ execution: TaskExecution; /** Worktree allocated for this task (if applicable) */ worktree?: Worktree; /** Worktree instructions to inject (if applicable) */ worktreeInstructions?: WorktreeInstructions; /** Modified task prompt with worktree context injected */ modifiedPrompt?: string; } export declare class TaskCoordinator { private activeExecutions; private logger; private stateCoordinator?; private worktreeManager?; private configManager?; private worktreeConfig?; constructor(options: TaskCoordinatorOptions); /** @deprecated Use options object instead */ constructor(logger: Logger); /** * Generate instructions for Claude to claim a task before execution. */ generateClaimInstructions(taskId: string, workerName: string): ClaimInstructions; /** * Check if a role needs an isolated worktree for execution. * Checks role config override first, then falls back to default role list. */ private taskNeedsWorktree; /** * Start tracking a task execution. */ startExecution(taskId: string, role: string, traceId?: string): TaskExecution; /** * Start a task execution with optional worktree allocation. * * This enhanced method: * 1. Creates task state via StateCoordinator (if available) * 2. Checks if the role needs a worktree * 3. Allocates worktree and generates instructions (if needed) * 4. Links task to worktree in state coordinator * 5. Returns modified prompt with worktree context injected * * @param taskId - Claude Code task ID * @param role - Agent role to execute * @param originalPrompt - Original task prompt/description * @param agentId - Optional agent ID for worktree allocation * @param traceId - Optional trace ID for correlation */ startExecutionWithWorktree(taskId: string, role: string, originalPrompt: string, agentId?: string, traceId?: string): Promise; /** * Get an active execution by task ID. */ getExecution(taskId: string): TaskExecution | undefined; /** * Mark execution complete and generate completion instructions. */ completeExecution(taskId: string, result: AgentResponse): CompletionResult; /** * Mark execution complete with worktree cleanup. * This is an async version that handles worktree release. */ completeExecutionWithWorktree(taskId: string, result: AgentResponse): Promise; /** * Mark execution failed and generate failure instructions. */ failExecution(taskId: string, error: Error): FailureResult; /** * Mark execution failed with worktree cleanup. * This is an async version that handles worktree release. */ failExecutionWithWorktree(taskId: string, error: Error): Promise; /** * Cleanup worktree associated with a task. * Releases the worktree and unlinks from state coordinator. */ cleanupWorktree(taskId: string): Promise; /** * Clear a completed/failed execution from tracking. */ clearExecution(taskId: string): void; /** * Get all active executions. */ getActiveExecutions(): TaskExecution[]; /** * Check if there are any active executions. */ hasActiveExecutions(): boolean; /** * Get worktree information for a task. * Returns undefined if no worktree is allocated. */ getWorktreeForTask(taskId: string): Worktree | undefined; /** * Check if worktree support is available and enabled. */ isWorktreeSupportEnabled(): boolean; /** * Get the state coordinator instance (if configured). */ getStateCoordinator(): StateCoordinator | undefined; /** * Get the worktree manager instance (if configured). */ getWorktreeManager(): WorktreeManager | undefined; /** * Delete a task and clean up associated worktree. * * @param taskId - Task to delete * @param options - Deletion options * @returns Result object with details about what was deleted */ deleteTask(taskId: string, options?: DeleteTaskOptions): Promise; } /** * Result of a task deletion operation */ export interface DeleteTaskResult { /** Whether the overall operation succeeded */ success: boolean; /** Whether the task was deleted from state */ taskDeleted: boolean; /** Whether an associated worktree was deleted */ worktreeDeleted: boolean; /** Error message if operation failed */ error?: string; } //# sourceMappingURL=coordinator.d.ts.map