import type { AgentTaskRoutingMetadata } from "../../contracts/agent-task-read-contract.js";
export type TaskStatus = "research" | "proposed" | "ready" | "in_progress" | "awaiting_review" | "awaiting_policy_approval" | "awaiting_external_decision" | "blocked" | "completed" | "cancelled";
export type TaskPriority = "P1" | "P2" | "P3";
export type TaskEntity = {
    id: string;
    status: TaskStatus;
    type: string;
    title: string;
    createdAt: string;
    updatedAt: string;
    archived?: boolean;
    archivedAt?: string;
    priority?: TaskPriority;
    dependsOn?: string[];
    unblocks?: string[];
    phase?: string;
    /** Stable phase identifier (e.g. `"28"`) for audits; optional on legacy tasks. */
    phaseKey?: string;
    metadata?: Record<string, unknown>;
    ownership?: string;
    approach?: string;
    /** Optional short summary (relational row column + update-task). */
    summary?: string;
    /** Optional longer description body. */
    description?: string;
    /** Optional risk label or note for maintainers. */
    risk?: string;
    technicalScope?: string[];
    acceptanceCriteria?: string[];
    /** Optional feature taxonomy slugs; persisted in `task_engine_task_features` when registry active (`user_version` 5+). */
    features?: string[];
    /** Stable routing projection for agent CLI JSON (omit when persisting — use `metadata` + relational columns). */
    agentRouting?: AgentTaskRoutingMetadata;
};
export type GuardResult = {
    allowed: boolean;
    guardName: string;
    code?: string;
    message?: string;
};
export type TransitionContext = {
    allTasks: TaskEntity[];
    timestamp: string;
    actor?: string;
    clientMutationId?: string;
    payloadDigest?: string;
};
export type TransitionGuard = {
    name: string;
    canTransition: (task: TaskEntity, targetState: TaskStatus, context: TransitionContext) => GuardResult;
};
export type TransitionEvidence = {
    transitionId: string;
    taskId: string;
    fromState: TaskStatus;
    toState: TaskStatus;
    action: string;
    clientMutationId?: string;
    payloadDigest?: string;
    guardResults: GuardResult[];
    dependentsUnblocked: string[];
    timestamp: string;
    actor?: string;
};
export type TaskStoreDocument = {
    schemaVersion: 1;
    tasks: TaskEntity[];
    transitionLog: TransitionEvidence[];
    mutationLog?: TaskMutationEvidence[];
    lastUpdated: string;
};
export type TaskMutationType = "create-task" | "update-task" | "archive-task" | "add-dependency" | "remove-dependency" | "create-task-from-plan" | "assign-task-phase" | "clear-task-phase" | "upsert-phase-catalog-entry";
export type TaskMutationEvidence = {
    mutationId: string;
    mutationType: TaskMutationType;
    taskId: string;
    timestamp: string;
    actor?: string;
    details?: Record<string, unknown>;
};
export type TaskEngineError = {
    code: TaskEngineErrorCode;
    message: string;
};
export type TaskEngineErrorCode = "invalid-transition" | "guard-rejected" | "dependency-unsatisfied" | "task-not-found" | "duplicate-task-id" | "invalid-task-schema" | "invalid-task-type-requirements" | "invalid-task-update" | "invalid-task-id-format" | "task-archived" | "dependency-cycle" | "duplicate-dependency" | "storage-read-error" | "storage-write-error" | "native-binding-arch-mismatch" | "invalid-adapter" | "import-parse-error" | "planning-generation-mismatch" | "planning-generation-required" | "workspace-status-import-conflict" | "workspace-revision-mismatch" | "unknown-feature-id" | "idempotency-key-conflict" | "hook-denied" | "phase-note-not-convertible";
export type TaskAdapter = {
    name: string;
    supports: () => TaskAdapterCapability[];
    load: () => Promise<TaskEntity[]>;
    save?: (tasks: TaskEntity[]) => Promise<void>;
};
export type TaskAdapterCapability = "read" | "write" | "watch";
export type NextActionSuggestion = {
    readyQueue: TaskEntity[];
    suggestedNext: TaskEntity | null;
    stateSummary: {
        research: number;
        proposed: number;
        ready: number;
        in_progress: number;
        awaiting_review: number;
        awaiting_policy_approval: number;
        awaiting_external_decision: number;
        blocked: number;
        completed: number;
        cancelled: number;
        total: number;
    };
    blockingAnalysis: BlockingAnalysisEntry[];
};
export type BlockingAnalysisEntry = {
    taskId: string;
    blockedBy: string[];
    blockingCount: number;
};
