/**
 * Cognigate - Constrained Execution Runtime
 *
 * Executes approved intents within defined constraints and resource limits.
 * Provides resource monitoring, memory tracking, and graceful termination.
 *
 * @packageDocumentation
 */
import type { Intent, Decision, ID } from '../common/types.js';
/**
 * Degradation levels for graceful degradation
 * Instead of hard termination, we progressively reduce capabilities
 */
export declare enum DegradationLevel {
    /** Normal operation - full capabilities */
    NONE = "none",
    /** Warning issued - monitoring increased */
    WARN = "warn",
    /** Resources throttled to 50% */
    THROTTLE = "throttle",
    /** Capabilities restricted - read-only mode */
    RESTRICT = "restrict",
    /** Execution suspended - awaiting human review */
    SUSPEND = "suspend"
}
/**
 * Degradation event emitted when an execution is degraded
 */
export interface DegradationEvent {
    intentId: ID;
    previousLevel: DegradationLevel;
    newLevel: DegradationLevel;
    reason: string;
    timestamp: string;
    resourceUsage: ResourceUsage;
}
/**
 * Callback for degradation events
 */
export type DegradationCallback = (event: DegradationEvent) => void | Promise<void>;
/**
 * Execution context for running an intent
 */
export interface ExecutionContext {
    intent: Intent;
    decision: Decision;
    resourceLimits: ResourceLimits;
}
/**
 * Resource limits for execution
 */
export interface ResourceLimits {
    maxMemoryMb: number;
    maxCpuPercent: number;
    timeoutMs: number;
    maxNetworkRequests?: number;
    maxFileSystemOps?: number;
}
/**
 * Execution result
 */
export interface ExecutionResult {
    intentId: ID;
    success: boolean;
    outputs: Record<string, unknown>;
    resourceUsage: ResourceUsage;
    startedAt: string;
    completedAt: string;
    error?: string;
}
/**
 * Resource usage metrics
 */
export interface ResourceUsage {
    memoryPeakMb: number;
    cpuTimeMs: number;
    wallTimeMs: number;
    networkRequests: number;
    fileSystemOps: number;
}
/**
 * Execution handler function type
 */
export type ExecutionHandler = (intent: Intent, context: Record<string, unknown>) => Promise<Record<string, unknown>>;
/**
 * Cognigate execution gateway
 */
export declare class CognigateGateway {
    private handlers;
    private activeExecutions;
    private defaultLimits;
    private degradationCallbacks;
    constructor(defaultLimits?: Partial<ResourceLimits>);
    /**
     * Get current memory usage in MB
     */
    private getMemoryUsageMb;
    /**
     * Start memory monitoring for an execution with graceful degradation support
     */
    private startMemoryMonitor;
    /**
     * Stop memory monitoring for an execution
     */
    private stopMemoryMonitor;
    /**
     * Register an execution handler for an intent type
     */
    registerHandler(intentType: string, handler: ExecutionHandler): void;
    /**
     * Execute an approved intent
     */
    execute(context: ExecutionContext): Promise<ExecutionResult>;
    /**
     * Execute handler with abort signal support
     */
    private executeWithAbort;
    /**
     * Create a timeout promise that also aborts the execution
     */
    private timeout;
    /**
     * Create empty resource usage
     */
    private emptyUsage;
    /**
     * Terminate an execution (kill switch)
     *
     * @param intentId - The intent ID to terminate
     * @returns true if the execution was found and terminated, false if not found
     */
    terminate(intentId: ID): Promise<boolean>;
    /**
     * Get the number of active executions
     */
    getActiveExecutionCount(): number;
    /**
     * Get IDs of all active executions
     */
    getActiveExecutionIds(): ID[];
    /**
     * Check if an execution is active
     */
    isExecutionActive(intentId: ID): boolean;
    /**
     * Register a callback for degradation events
     */
    onDegradation(callback: DegradationCallback): void;
    /**
     * Apply a degradation level to an execution
     * This is the core of graceful degradation - instead of terminating,
     * we progressively reduce capabilities
     */
    private applyDegradation;
    /**
     * Get numeric severity for degradation level comparison
     */
    private getDegradationSeverity;
    /**
     * Manually degrade an execution (e.g., from policy violation)
     * This allows external systems (BASIS, escalation) to degrade executions
     *
     * @param intentId - The intent ID to degrade
     * @param level - The degradation level to apply
     * @param reason - Human-readable reason for degradation
     * @returns true if degradation was applied, false if execution not found
     */
    degrade(intentId: ID, level: DegradationLevel, reason: string): boolean;
    /**
     * Get the current degradation level of an execution
     */
    getDegradationLevel(intentId: ID): DegradationLevel | undefined;
    /**
     * Get effective (possibly reduced) limits for an execution
     */
    getEffectiveLimits(intentId: ID): ResourceLimits | undefined;
    /**
     * Restore an execution from suspension (requires human approval)
     * This is called after HITL review approves continuation
     *
     * @param intentId - The intent ID to restore
     * @param newLimits - Optional new limits to apply
     * @returns true if restored, false if execution not found or not suspended
     */
    restore(intentId: ID, newLimits?: Partial<ResourceLimits>): boolean;
}
/**
 * Create a new Cognigate gateway instance
 */
export declare function createGateway(defaultLimits?: Partial<ResourceLimits>): CognigateGateway;
export * from './sandbox/index.js';
//# sourceMappingURL=index.d.ts.map