import { QualityIntelligence as QI } from "@oscharko-dev/keiko-contracts";
import { type QualityIntelligenceCoverageMatrixRow, type QualityIntelligenceLocalStore, type QualityIntelligenceRecordInput, type QualityIntelligenceRecordResult } from "@oscharko-dev/keiko-evidence";
import { type AtomCoverageStatus, type PolicyProfile } from "@oscharko-dev/keiko-quality-intelligence";
import type { QualityIntelligenceWorkflowDescriptor, QualityIntelligenceWorkflowLimits } from "./descriptors.js";
/** Sink for QI run events. Mirrors the harness EventSink shape but typed for the QI envelope. */
export interface QualityIntelligenceRunEventSink {
    readonly emit: (event: QI.QualityIntelligenceRunEvent) => void;
}
/** Wall-clock port. Defaults to `Date.now`; injected for deterministic tests. */
export interface QualityIntelligenceClock {
    readonly nowIso: () => string;
}
export declare const DEFAULT_CLOCK: QualityIntelligenceClock;
export type QualityIntelligenceProvenanceRefs = QualityIntelligenceRecordInput["provenanceRefs"];
export type QualityIntelligenceRunStatus = "succeeded" | "failed" | "cancelled";
export interface QualityIntelligenceRunSummary {
    readonly runId: QI.QualityIntelligenceRunId;
    readonly workflowId: QualityIntelligenceWorkflowDescriptor["workflowId"];
    readonly status: QualityIntelligenceRunStatus;
    readonly eventsEmitted: number;
    readonly modelGatewayCallCount: number;
    readonly evidence?: QualityIntelligenceRecordResult | undefined;
    readonly reasonSummary?: string | undefined;
    /**
     * Run quality score: the percentage of judged candidates the adversarial judge rated "strong"
     * [0-100] (Epic #736). Null when the judge stage was skipped, unavailable, or no candidate was
     * judged.
     */
    readonly qualityScore?: number | null;
}
export interface RunContext {
    readonly descriptor: QualityIntelligenceWorkflowDescriptor;
    readonly plan: QI.QualityIntelligenceRunPlan;
    readonly sink: QualityIntelligenceRunEventSink;
    readonly clock: QualityIntelligenceClock;
    readonly limits: QualityIntelligenceWorkflowLimits;
    readonly profile: PolicyProfile;
    readonly signal: AbortSignal | undefined;
    sequence: number;
    modelGatewayCallCount: number;
}
export interface RunContextInit {
    readonly descriptor: QualityIntelligenceWorkflowDescriptor;
    readonly plan: QI.QualityIntelligenceRunPlan;
    readonly sink: QualityIntelligenceRunEventSink;
    readonly clock?: QualityIntelligenceClock | undefined;
    readonly limits?: QualityIntelligenceWorkflowLimits | undefined;
    readonly policyProfile?: PolicyProfile | undefined;
    readonly signal?: AbortSignal | undefined;
}
export declare function makeContext(init: RunContextInit): RunContext;
export declare function emit(ctx: RunContext, payload: QI.QualityIntelligenceRunEventPayload): void;
export declare function emitQueuedAndStarted(ctx: RunContext): void;
export declare class StageCancelledError extends Error {
    constructor();
}
export declare function checkCancelled(ctx: RunContext): void;
export declare function safeReasonSummary(error: unknown): string;
export declare function withStage<T>(ctx: RunContext, stageName: string, body: () => Promise<T>): Promise<T>;
export declare function truncateCandidates(candidates: readonly QI.QualityIntelligenceTestCaseCandidate[], limit: number): readonly QI.QualityIntelligenceTestCaseCandidate[];
export declare function truncateFindings(findings: readonly QI.QualityIntelligenceValidationFinding[], limit: number): readonly QI.QualityIntelligenceValidationFinding[];
/**
 * Project per-atom coverage statuses into persistable matrix rows (Epic #734). When the caller
 * supplies `excerptByAtomId` (atom id -> already-redacted excerpt, see `buildRequirementExcerpt`),
 * each row additionally carries `requirementExcerptRedacted` so coverage/traceability surfaces are
 * auditor-readable (#790); rows without a map entry stay refs-only.
 */
export declare function toCoverageMatrixRows(statuses: readonly AtomCoverageStatus[], excerptByAtomId?: ReadonlyMap<string, string>): readonly QualityIntelligenceCoverageMatrixRow[];
/**
 * Build the persistable coverage matrix for a run from its atoms + candidates. Used by every run
 * path so coverage is persisted consistently (the scripted paths previously discarded it).
 */
export declare function coverageMatrixFor(runId: QI.QualityIntelligenceRunId, atoms: readonly QI.QualityIntelligenceEvidenceAtom[], candidates: readonly QI.QualityIntelligenceTestCaseCandidate[], excerptByAtomId?: ReadonlyMap<string, string>): readonly QualityIntelligenceCoverageMatrixRow[];
export declare function emitCandidateProposed(ctx: RunContext, candidates: readonly QI.QualityIntelligenceTestCaseCandidate[]): void;
export declare function emitFindingsRecorded(ctx: RunContext, findings: readonly QI.QualityIntelligenceValidationFinding[]): void;
export type EvidenceStatus = "running" | "succeeded" | "failed" | "cancelled";
export interface PersistArgs {
    readonly ctx: RunContext;
    readonly status: EvidenceStatus;
    readonly candidatesCount: number;
    readonly findings: readonly QI.QualityIntelligenceValidationFinding[];
    readonly evidenceRefs?: QualityIntelligenceRecordInput["evidenceRefs"] | undefined;
    readonly provenanceRefs: QualityIntelligenceProvenanceRefs;
    readonly completedAt: string | undefined;
    readonly evidenceStore: QualityIntelligenceLocalStore;
    readonly coverageMatrix?: QualityIntelligenceRecordInput["coverageMatrix"];
    readonly qualityScore?: number | null;
    readonly sourceFingerprints?: QualityIntelligenceRecordInput["sourceFingerprints"];
    readonly atomFingerprints?: QualityIntelligenceRecordInput["atomFingerprints"];
    /** Model id that generated the candidates (Epic #761). */
    readonly modelId?: string;
    /** Redaction-safe request parameter scalars (Epic #761). */
    readonly modelParameters?: Record<string, unknown>;
    /** Seed used for deterministic sampling (Epic #761). */
    readonly seedUsed?: number | null;
}
export declare function persistRun(args: PersistArgs): QualityIntelligenceRecordResult;
export interface FinaliseArgs {
    readonly candidatesCount: number;
    readonly findings: readonly QI.QualityIntelligenceValidationFinding[];
    readonly evidenceRefs?: QualityIntelligenceRecordInput["evidenceRefs"] | undefined;
    readonly provenanceRefs: QualityIntelligenceProvenanceRefs;
    readonly evidenceStore: QualityIntelligenceLocalStore;
}
export declare function finaliseFailureOrCancellation(ctx: RunContext, caught: unknown, args: FinaliseArgs): QualityIntelligenceRunSummary;
//# sourceMappingURL=runtimeCommon.d.ts.map