/**
 * ExternalCrossCheckEnforcer -- Opt-in external verification gate for self-reflection outcomes.
 *
 * A self-reflecting agent (Tier 1, Agent Type Coverage Strategy) produces a reflection
 * outcome (self-check verdict). This primitive bounds the trust placed in that single
 * self-reflection by requiring an external cross-check before the cycle proceeds.
 *
 * ORTHOGONAL TO the SelfReflectionLoopDetector (anomaly-self-reflection.ts):
 *   - LoopDetector: catches pathological loops (N consecutive regenerate triplets).
 *   - ExternalCrossCheckEnforcer: limits trust in any single self-reflection outcome,
 *     regardless of whether a loop exists.
 *
 * Two operating modes (operator-configured per agent):
 *   'peer-agent'  -- Reflection outcome is forwarded to a designated peer agent
 *                    (different model / different prompt). Peer returns a verdict.
 *                    Accept -> cycle continues. Reject or inconclusive -> human queue.
 *   'human-only'  -- Every reflection outcome creates a human approval queue entry.
 *                    No peer agent is involved.
 *
 * Pen-test coverage:
 *   PT-CROSS-CHECK-1: Peer-collusion detection via agreement-rate tracking.
 *   PT-CROSS-CHECK-2: Tier-spoofing prevention via queue auth check.
 *   PT-CROSS-CHECK-3: Cycle-replay prevention via terminated-cycle guard.
 *
 * Compliance bindings:
 *   - EU AI Act Art. 14: Human oversight of high-risk AI outputs.
 *   - HIPAA 164.308(a)(3): Workforce controls for access to PHI processing agents.
 *   - SOC 2 CC1.4: Control environment -- independent verification of agent output.
 *   - ISO 27001 A.6.1.1: Information security roles and responsibilities.
 *   - NIST 800-53 AU-12: Audit record generation -- cross-check outcome logged.
 *
 * BUILD_PLAN V3 line 259: External cross-check option (second agent or human verifies
 * reflection outcome via approval queue).
 *
 * @connexum/ai-governance
 */
import { AuditIntegrity } from '../audit/audit-integrity';
import { ApprovalQueue } from '../governance/approval-queue';
/** Approval-queue tier string for all entries created by this enforcer. */
export declare const SELF_REFLECTION_CROSS_CHECK_TIER = "SELF_REFLECTION_CROSS_CHECK";
export declare class CrossCheckConfigError extends Error {
    constructor(message: string);
}
export declare class CycleAlreadyTerminatedError extends Error {
    readonly cycleId: string;
    constructor(cycleId: string, reason?: string);
}
export type CrossCheckMode = 'peer-agent' | 'human-only';
export type PeerVerdict = 'accept' | 'reject' | 'inconclusive';
export interface PeerAgentVerdictRequest {
    agentId: string;
    peerAgentId: string;
    reflectionOutcome: ReflectionOutcome;
}
export interface PeerAgentVerdictResponse {
    verdict: PeerVerdict;
    confidence: number;
    reasoning?: string;
}
/**
 * Operator-supplied callback to invoke the peer agent.
 * The enforcer does NOT ship a peer-agent runner; operators wire their own.
 */
export type PeerAgentVerdictCallback = (request: PeerAgentVerdictRequest) => Promise<PeerAgentVerdictResponse>;
export interface ReflectionOutcome {
    kind: 'self-check';
    verdict: 'accept' | 'regenerate';
    text?: string;
}
export interface CrossCheckConfig {
    mode: CrossCheckMode;
    /** Required when mode is 'peer-agent'. Must differ from agentId. */
    peerAgentId?: string;
    /**
     * Compliance pack IDs governing this cross-check.
     * Must be non-empty (pack-binding primacy invariant).
     */
    packBinding: string[];
    /**
     * Milliseconds to wait for the peer agent before treating as inconclusive.
     * Default: 10_000.
     */
    peerTimeoutMs?: number;
    /**
     * Size of the rolling window for PT-CROSS-CHECK-1 collusion detection.
     * Default: 20.
     */
    collusionWindow?: number;
    /**
     * Accept-rate fraction at or above which PEER_COLLUSION_SUSPECTED is emitted.
     * Default: 1.0 (100% accepts).
     */
    collusionAcceptThreshold?: number;
}
/** Outcome of evaluateReflection. */
export interface CrossCheckResult {
    /**
     * 'continue'   -- peer accepted; cycle may proceed.
     * 'queued'     -- queued for human review (peer rejected / inconclusive / human-only mode).
     * 'terminated' -- cycle was previously terminated; this call is a no-op guard.
     */
    status: 'continue' | 'queued' | 'terminated';
    /** Approval queue entry ID when status is 'queued'. */
    approvalId?: string;
    /** Peer verdict when in peer-agent mode. */
    peerVerdict?: PeerVerdict;
    /** Whether collusion was suspected in this evaluation. */
    collusionSuspected?: boolean;
}
/** Outcome of resumeFromApproval. */
export interface ResumeResult {
    status: 'continue' | 'terminated';
}
export declare class ExternalCrossCheckEnforcer {
    private readonly peerCallback?;
    private readonly auditIntegrity?;
    private readonly approvalQueue;
    /** Registry: `${orgId}::${agentId}` -> config */
    private readonly configs;
    /**
     * Registry: approvalId -> { orgId, agentId, cycleId, packBinding }
     * Used by resumeFromApproval to retrieve the cycle context.
     */
    private readonly pendingResumes;
    /**
     * Terminated cycles: `${orgId}::${agentId}::${cycleId}`
     * Populated when resumeFromApproval returns 'terminated'.
     * PT-CROSS-CHECK-3: guards against cycle replay under the same cycleId.
     */
    private readonly terminatedCycles;
    /** Stale queue entries that were auto-resolved due to cycle replay. */
    private readonly staleResolvedEntries;
    private readonly collusionTracker;
    constructor(opts: {
        approvalQueue: ApprovalQueue;
        peerCallback?: PeerAgentVerdictCallback;
        auditIntegrity?: AuditIntegrity;
    });
    /**
     * Register a cross-check rule for an agent.
     *
     * @throws {CrossCheckConfigError} if packBinding is empty.
     * @throws {CrossCheckConfigError} if mode is 'peer-agent' and peerAgentId equals agentId.
     * @throws {CrossCheckConfigError} if mode is 'peer-agent' and peerAgentId is not supplied.
     */
    configure(orgId: string, agentId: string, mode: CrossCheckMode, peerAgentId?: string, packBinding?: string[], opts?: {
        peerTimeoutMs?: number;
        collusionWindow?: number;
        collusionAcceptThreshold?: number;
    }): void;
    /**
     * Evaluate a self-reflection outcome.
     *
     * In 'peer-agent' mode:
     *   - Invokes the PeerAgentVerdictCallback with a timeout.
     *   - 'accept' -> emit SELF_REFLECTION_CROSS_CHECK_PASSED (NOTICE); returns { status: 'continue' }.
     *   - 'reject' | 'inconclusive' -> emit SELF_REFLECTION_CROSS_CHECK_DISAGREEMENT (WARNING);
     *     create SELF_REFLECTION_CROSS_CHECK queue entry; returns { status: 'queued', approvalId }.
     *   - Peer timeout -> treated as 'inconclusive'.
     *
     * In 'human-only' mode:
     *   - Always creates a queue entry; returns { status: 'queued', approvalId }.
     *
     * Reflection text is NEVER stored. Only its SHA-256 hash enters the audit chain.
     *
     * @throws {Error} if no config is registered for this agent.
     * @throws {CycleAlreadyTerminatedError} if the cycle was already terminated.
     */
    evaluateReflection(orgId: string, agentId: string, cycleId: string, reflectionOutcome: ReflectionOutcome): Promise<CrossCheckResult>;
    /**
     * Called by the approval-queue resolver when a human resolves a
     * SELF_REFLECTION_CROSS_CHECK queue entry.
     *
     * approved: true  -> { status: 'continue' }
     * approved: false -> marks cycle as terminated, { status: 'terminated' }
     *
     * PT-CROSS-CHECK-3: once a cycle is terminated, any subsequent evaluateReflection
     * call for the same cycleId throws CycleAlreadyTerminatedError.
     *
     * PT-CROSS-CHECK-2: this method does NOT bypass the approval-queue's auth check.
     * The queue's resolve() method validates the resolvedBy identity and HMAC token
     * before this is called. Self-approval is blocked at the queue layer.
     *
     * @throws {Error} if approvalId is not tracked by this enforcer.
     */
    resumeFromApproval(approvalId: string, approved: boolean, resolvedBy?: string): ResumeResult;
    /**
     * Auto-resolve any pending queue entries for a terminated cycleId as
     * 'terminated_by_cycle_replay'. Called when a new cycle attempts to use
     * a cycleId that was already terminated.
     */
    resolveStaleEntriesForCycle(orgId: string, agentId: string, cycleId: string): string[];
    /** Whether a cross-check config is registered for this agent. */
    isConfigured(orgId: string, agentId: string): boolean;
    /** Whether a cycle is marked as terminated. */
    isCycleTerminated(orgId: string, agentId: string, cycleId: string): boolean;
    /** Expose the collusion tracker for testing PT-CROSS-CHECK-1. */
    getPeerAgreementWindow(peerAgentId: string): boolean[];
    private configKey;
    private cycleKey;
    private getConfig;
    private invokePeer;
    private createQueueEntry;
    private emitAuditEvent;
}
//# sourceMappingURL=external-cross-check.d.ts.map