import type { ACPSessionRecord } from '@coralai/claude-code-agent';
import type { CardState } from '../shared/types.js';
export interface WorkerSlotState {
    status: 'idle' | 'active' | 'merging' | 'resolving' | 'releasing';
    seq: number | null;
    branch: string | null;
    worktree: string | null;
    claimedAt: string | null;
    lastHeartbeat: string | null;
    /** Worker execution mode — null for legacy state files */
    mode?: 'print' | 'acp' | 'acp-sdk' | null;
    /** Underlying worker transport */
    transport?: 'acp-sdk' | null;
    /** Worker tool currently bound to the slot */
    agent?: 'claude' | null;
    /** Claude session ID for resume chains (print mode, legacy) */
    sessionId?: string | null;
    /** ACP run ID for the active task */
    runId?: string | null;
    /** ACP session lifecycle status */
    sessionState?: 'booting' | 'ready' | 'busy' | 'needs_confirmation' | 'draining' | 'offline' | null;
    /** ACP run lifecycle status */
    remoteStatus?: 'submitted' | 'running' | 'waiting_input' | 'needs_confirmation' | 'stalled_submit' | 'completed' | 'failed' | 'cancelled' | 'lost' | null;
    /** Last ACP event timestamp observed by SPS */
    lastEventAt?: string | null;
    /** OS process ID of the worker (print mode) */
    pid?: number | null;
    /** Path to the JSONL output file (print mode) */
    outputFile?: string | null;
    /** Process exit code — null while running (print mode) */
    exitCode?: number | null;
    /** Number of L2 merge conflict resolution attempts */
    mergeRetries?: number;
    /** When worker finished coding (ISO string, for merge queue FIFO ordering) */
    completedAt?: string | null;
}
export interface ActiveCardState {
    seq: number;
    state: string;
    worker: string | null;
    mrUrl: string | null;
    conflictDomains: string[];
    startedAt: string;
    /** Number of times this card has been auto-retried */
    retryCount?: number;
}
export interface WorktreeCleanupEntry {
    branch: string;
    worktreePath: string;
    markedAt: string;
}
export type TaskLeasePhase = 'queued' | 'preparing' | 'coding' | 'merging' | 'resolving_conflict' | 'waiting_confirmation' | 'suspended' | 'closing' | 'released';
export interface TaskLease {
    seq: number;
    pmStateObserved: CardState | null;
    phase: TaskLeasePhase;
    slot: string | null;
    branch: string | null;
    worktree: string | null;
    sessionId: string | null;
    runId: string | null;
    claimedAt: string | null;
    retryCount: number;
    lastTransitionAt: string;
}
export type WorktreeEvidenceStatus = 'missing' | 'clean' | 'dirty' | 'rebase' | 'merge' | 'conflict';
export interface WorktreeEvidence {
    seq: number;
    branch: string | null;
    worktree: string | null;
    worktreeExists: boolean;
    branchExists: boolean;
    gitStatus: WorktreeEvidenceStatus;
    pushed: boolean;
    mergedToBase: boolean;
    aheadOfBase: number;
    behindBase: number;
    lastCheckedAt: string;
}
export interface PendingPMAction {
    type: 'move' | 'comment' | 'label' | 'release';
    taskId: string;
    project: string;
    target?: string;
    message?: string;
    createdAt: string;
    retryCount: number;
}
export interface IntegrationQueueEntry {
    taskId: string;
    cardId: string;
    project: string;
    prompt: string;
    cwd: string;
    branch: string;
    targetBranch: string;
    tool: 'claude';
    transport: 'acp-sdk';
    outputFile: string;
    enqueuedAt: string;
}
export interface IntegrationQueueState {
    active: IntegrationQueueEntry | null;
    waiting: IntegrationQueueEntry[];
}
export interface RuntimeState {
    version: number;
    generation: number;
    updatedAt: string;
    updatedBy: string;
    workers: Record<string, WorkerSlotState>;
    activeCards: Record<string, ActiveCardState>;
    leases: Record<string, TaskLease>;
    worktreeEvidence: Record<string, WorktreeEvidence>;
    worktreeCleanup: WorktreeCleanupEntry[];
    /** ACP session records — merged from former acp-state.json */
    sessions: Record<string, ACPSessionRecord>;
    /** Per-project:targetBranch integration serialisation queues */
    integrationQueues: Record<string, IntegrationQueueState>;
    /** PM operations that failed and need retry on next tick cycle */
    pendingPMActions: PendingPMAction[];
}
export declare function createIdleWorkerSlot(): WorkerSlotState;
export declare function readState(stateFile: string, maxWorkers: number): RuntimeState;
/**
 * Atomic write: write to temp file, then rename.
 * Increments generation automatically.
 */
export declare function writeState(stateFile: string, state: RuntimeState, updatedBy: string): void;
//# sourceMappingURL=state.d.ts.map