/**
 * Worker Task Service
 *
 * This service provides the complete workflow for workers picking up tasks
 * and working in isolated worktrees. It orchestrates:
 * - Task dispatch to worker
 * - Worktree creation for task isolation
 * - Worker spawning in the worktree
 * - Task context delivery to worker
 * - Task completion with branch ready for merge
 *
 * @module
 */
import type { Task, ElementId, EntityId, Timestamp } from '@stoneforge/core';
import type { QuarryAPI } from '@stoneforge/quarry';
import type { AgentEntity } from '../api/orchestrator-api.js';
import type { TaskAssignmentService } from './task-assignment-service.js';
import type { AgentRegistry } from './agent-registry.js';
import type { DispatchService, DispatchResult } from './dispatch-service.js';
import type { WorktreeManager, CreateWorktreeResult, WorktreeInfo } from '../git/worktree-manager.js';
import type { SpawnerService } from '../runtime/spawner.js';
import type { SessionManager, SessionRecord } from '../runtime/session-manager.js';
/**
 * Options for starting a worker on a task
 */
export interface StartWorkerOnTaskOptions {
    /** Custom branch name (auto-generated if not provided) */
    branch?: string;
    /** Custom worktree path (auto-generated if not provided) */
    worktreePath?: string;
    /** Base branch to create the worktree from (defaults to default branch) */
    baseBranch?: string;
    /** Additional initial prompt to prepend to task context */
    additionalPrompt?: string;
    /** Entity performing the operation */
    performedBy?: EntityId;
    /** Skip worktree creation (use existing working directory) */
    skipWorktree?: boolean;
    /** Custom working directory (used if skipWorktree is true) */
    workingDirectory?: string;
    /** Dispatch priority for notification */
    priority?: number;
}
/**
 * Result of starting a worker on a task
 */
export interface StartWorkerOnTaskResult {
    /** The task being worked on */
    task: Task;
    /** The worker agent */
    agent: AgentEntity;
    /** The dispatch result (notification sent) */
    dispatch: DispatchResult;
    /** The worktree created (if applicable) */
    worktree?: CreateWorktreeResult;
    /** The session spawned */
    session: SessionRecord;
    /** The task context prompt that was sent */
    taskContextPrompt: string;
    /** Timestamp when the worker started */
    startedAt: Timestamp;
}
/**
 * Options for completing a task
 */
export interface CompleteTaskOptions {
    /** Summary of what was accomplished */
    summary?: string;
    /** Commit hash for the final commit */
    commitHash?: string;
    /** Whether to run tests before marking complete (defaults to false) */
    runTests?: boolean;
    /** Entity performing the completion */
    performedBy?: EntityId;
}
/**
 * Result of completing a task
 */
export interface CompleteTaskResult {
    /** The completed task */
    task: Task;
    /** The worktree info (if applicable) */
    worktree?: WorktreeInfo;
    /** Whether the branch is ready for merge */
    readyForMerge: boolean;
    /** Timestamp when the task was completed */
    completedAt: Timestamp;
}
/**
 * Task context information for generating prompts
 */
export interface TaskContext {
    /** Task ID */
    taskId: ElementId;
    /** Task title */
    title: string;
    /** Task description (from metadata) */
    description?: string;
    /** Task tags */
    tags: string[];
    /** Task priority (enum value) */
    priority?: number;
    /** Task complexity (enum value) */
    complexity?: number;
    /** Branch name */
    branch?: string;
    /** Worktree path */
    worktreePath?: string;
    /** Additional instructions */
    additionalInstructions?: string;
}
/**
 * Worker Task Service interface for orchestrating worker task workflow.
 *
 * This service provides the complete lifecycle management for workers:
 * 1. Start worker on a task (dispatch + worktree + spawn)
 * 2. Build task context prompts
 * 3. Complete tasks (close + ready for merge)
 * 4. Clean up after task completion
 */
export interface WorkerTaskService {
    /**
     * Starts a worker on a task with full worktree isolation.
     *
     * This method performs the complete workflow:
     * 1. Dispatches the task to the worker (assigns + notifies)
     * 2. Creates a worktree for the task (if worktrees enabled)
     * 3. Spawns the worker session in the worktree
     * 4. Sends task context to the worker
     *
     * @param taskId - The task to start
     * @param agentId - The worker agent
     * @param options - Options for starting
     * @returns The complete result
     */
    startWorkerOnTask(taskId: ElementId, agentId: EntityId, options?: StartWorkerOnTaskOptions): Promise<StartWorkerOnTaskResult>;
    /**
     * Completes a task and marks the branch as ready for merge.
     *
     * This method:
     * 1. Marks the task as completed
     * 2. Updates merge status to 'pending' (ready for Merge Steward)
     * 3. Optionally runs tests
     *
     * @param taskId - The task to complete
     * @param options - Completion options
     * @returns The completion result
     */
    completeTask(taskId: ElementId, options?: CompleteTaskOptions): Promise<CompleteTaskResult>;
    /**
     * Builds the task context prompt for a worker.
     *
     * @param taskId - The task
     * @param workerId - The worker entity ID
     * @param additionalInstructions - Additional instructions to include
     * @returns The formatted task context prompt
     */
    buildTaskContextPrompt(taskId: ElementId, workerId: EntityId, additionalInstructions?: string): Promise<string>;
    /**
     * Gets the task context information.
     *
     * @param taskId - The task
     * @returns The task context
     */
    getTaskContext(taskId: ElementId): Promise<TaskContext>;
    /**
     * Cleans up after a task is merged or abandoned.
     *
     * This method:
     * 1. Removes the worktree
     * 2. Optionally deletes the branch
     * 3. Updates task metadata
     *
     * @param taskId - The task to clean up
     * @param deleteBranch - Whether to delete the branch
     * @returns Success status
     */
    cleanupTask(taskId: ElementId, deleteBranch?: boolean): Promise<boolean>;
}
/**
 * Implementation of the Worker Task Service.
 */
export declare class WorkerTaskServiceImpl implements WorkerTaskService {
    private readonly api;
    private readonly taskAssignment;
    private readonly agentRegistry;
    private readonly dispatchService;
    private readonly worktreeManager;
    private readonly _spawnerService;
    private readonly sessionManager;
    constructor(api: QuarryAPI, taskAssignment: TaskAssignmentService, agentRegistry: AgentRegistry, dispatchService: DispatchService, spawnerService: SpawnerService, sessionManager: SessionManager, worktreeManager?: WorktreeManager);
    startWorkerOnTask(taskId: ElementId, agentId: EntityId, options?: StartWorkerOnTaskOptions): Promise<StartWorkerOnTaskResult>;
    completeTask(taskId: ElementId, options?: CompleteTaskOptions): Promise<CompleteTaskResult>;
    buildTaskContextPrompt(taskId: ElementId, workerId: EntityId, additionalInstructions?: string): Promise<string>;
    getTaskContext(taskId: ElementId): Promise<TaskContext>;
    cleanupTask(taskId: ElementId, deleteBranch?: boolean): Promise<boolean>;
}
/**
 * Creates a WorkerTaskService instance
 */
export declare function createWorkerTaskService(api: QuarryAPI, taskAssignment: TaskAssignmentService, agentRegistry: AgentRegistry, dispatchService: DispatchService, spawnerService: SpawnerService, sessionManager: SessionManager, worktreeManager?: WorktreeManager): WorkerTaskService;
//# sourceMappingURL=worker-task-service.d.ts.map