import { EventEmitter } from "node:events";
/** Raw MCP tool result content block */
export interface McpContentBlock {
    type: string;
    text?: string;
    data?: string;
    mimeType?: string;
    [key: string]: unknown;
}
/** Raw MCP CallToolResult */
export interface McpCallToolResult {
    content: McpContentBlock[];
    isError?: boolean;
}
/** Model-facing compressed result for LLM context */
export interface ModelFacingResult {
    /** Summarized text content (truncated if needed) */
    summary: string;
    /** Whether the tool call succeeded */
    success: boolean;
    /** Content type hints for the model */
    contentTypes: string[];
    /** Total character count of original result */
    originalSize: number;
    /** Compression ratio achieved */
    compressionRatio: number;
}
/** Evidence-facing raw result for debugging/QA */
export interface EvidenceFacingResult {
    /** Full raw content blocks */
    content: McpContentBlock[];
    /** Whether the tool call errored */
    isError: boolean;
    /** Server that provided the result */
    serverName: string;
    /** Tool name that was called */
    toolName: string;
    /** Arguments passed (sanitized — no secrets) */
    sanitizedArgs: Record<string, unknown>;
}
/** Audit-facing immutable record for compliance */
export interface AuditRecord {
    /** Unique record ID */
    id: string;
    /** ISO 8601 timestamp */
    timestamp: string;
    /** Tool name */
    toolName: string;
    /** Server name */
    serverName: string;
    /** SHA-256 hash of arguments (for dedup/correlation) */
    argsHash: string;
    /** SHA-256 hash of raw result */
    resultHash: string;
    /** Number of content blocks */
    contentBlockCount: number;
    /** Whether secrets were redacted */
    secretsRedacted: boolean;
    /** Number of secrets found and redacted */
    secretCount: number;
    /** Whether the result was truncated */
    truncated: boolean;
    /** Execution duration in milliseconds */
    durationMs: number;
    /** Whether the call errored */
    isError: boolean;
    /** Error message if isError */
    errorMessage?: string;
}
/** Full governed tool result with all three channels */
export interface GovernedToolResult {
    /** Model-facing: compressed for LLM context */
    model: ModelFacingResult;
    /** Evidence-facing: raw for debugging */
    evidence: EvidenceFacingResult;
    /** Audit-facing: immutable record */
    audit: AuditRecord;
}
export interface ToolGovernancePolicy {
    /** Tool name patterns to allow (glob-style, null = allow all) */
    allowTools: string[] | null;
    /** Tool name patterns to deny */
    denyTools: string[];
    /** Maximum content size in chars before truncation (default: 4000) */
    maxModelContentChars: number;
    /** Whether to enable secret redaction (default: true) */
    enableSecretRedaction: boolean;
    /** Whether to enable audit logging (default: true) */
    enableAuditLog: boolean;
    /** Maximum audit log entries (ring buffer, default: 1000) */
    maxAuditEntries: number;
    /** Custom secret patterns to add to defaults */
    customSecretPatterns?: RegExp[];
    /** Tools that bypass governance entirely (raw passthrough) */
    bypassGovernance: string[];
}
/** Permission level for MCP tool access */
export declare enum ToolPermissionLevel {
    /** Tool is allowed without additional consent */
    ALLOW = "allow",
    /** Tool requires explicit user consent before execution */
    ASK = "ask",
    /** Tool is denied — cannot be executed */
    DENY = "deny"
}
/** A single tool permission rule matching tool name patterns */
export interface ToolPermissionRule {
    /** Glob-style tool name pattern (e.g. "github:*", "browser_click") */
    pattern: string;
    /** Permission level for matching tools */
    permission: ToolPermissionLevel;
    /** Optional reason for audit trail */
    reason?: string;
    /** Rule priority — higher overrides lower (default: 0) */
    priority?: number;
}
/** Resolved permission for a specific tool invocation */
export interface ResolvedToolPermission {
    /** Final permission level */
    permission: ToolPermissionLevel;
    /** Rule that determined this permission (null = default) */
    matchedRule: ToolPermissionRule | null;
    /** Whether this was resolved from server-level policy */
    serverLevel: boolean;
    /** Whether governance layer bypass is active */
    governanceBypass: boolean;
}
/** Severity level for governance rules */
export declare enum RuleSeverity {
    /** Critical — always blocks, cannot be overridden by lower-priority rules */
    CRITICAL = "critical",
    /** High — blocks unless explicitly overridden */
    HIGH = "high",
    /** Medium — standard rule, follows normal priority resolution */
    MEDIUM = "medium",
    /** Low — advisory, only applies if no higher-severity rule matches */
    LOW = "low",
    /** Info — informational only, logged but not enforced */
    INFO = "info"
}
/** Extended permission rule with severity and server scoping */
export interface GovernanceRule extends ToolPermissionRule {
    /** Rule severity level (default: MEDIUM) */
    severity?: RuleSeverity;
    /** MCP server name this rule applies to (null = all servers) */
    serverName?: string;
    /** Rule category for grouping/filtering */
    category?: string;
    /** Whether this rule is currently enabled */
    enabled?: boolean;
    /** ISO 8601 timestamp when the rule was created */
    createdAt?: string;
}
/** Named governance rule preset */
export interface GovernancePreset {
    /** Preset identifier (e.g. "strict", "permissive", "development") */
    name: string;
    /** Human-readable description */
    description: string;
    /** Rules included in this preset */
    rules: GovernanceRule[];
    /** Default permission level when no rule matches */
    defaultPermission: ToolPermissionLevel;
}
/** Create a GovernanceRule with defaults */
export declare function createRule(pattern: string, permission: ToolPermissionLevel, options?: {
    severity?: RuleSeverity;
    reason?: string;
    priority?: number;
    serverName?: string;
    category?: string;
}): GovernanceRule;
/** Strict preset — deny by default, only explicitly allowed tools pass */
export declare const STRICT_PRESET: GovernancePreset;
/** Permissive preset — allow most operations, only deny dangerous ones */
export declare const PERMISSIVE_PRESET: GovernancePreset;
/** Development preset — balanced for local dev work */
export declare const DEVELOPMENT_PRESET: GovernancePreset;
/** All available presets */
export declare const GOVERNANCE_PRESETS: Record<string, GovernancePreset>;
/** Get a preset by name */
export declare function getPreset(name: string): GovernancePreset | undefined;
/** List all available preset names */
export declare function listPresets(): string[];
export declare function redactSecrets(text: string, customPatterns?: RegExp[]): {
    redacted: string;
    count: number;
};
export declare function compressResult(content: McpContentBlock[], maxChars: number): {
    summary: string;
    truncated: boolean;
    originalSize: number;
};
export declare function sanitizeArgs(args: Record<string, unknown>): Record<string, unknown>;
export declare class AuditLogger extends EventEmitter {
    private buffer;
    private maxSize;
    constructor(maxSize?: number);
    /** Add a record to the audit log (ring buffer) */
    add(record: AuditRecord): void;
    /** Get all audit records */
    getAll(): AuditRecord[];
    /** Get last N records */
    getLast(n: number): AuditRecord[];
    /** Get records for a specific tool */
    getByTool(toolName: string): AuditRecord[];
    /** Get records for a specific server */
    getByServer(serverName: string): AuditRecord[];
    /** Get error records only */
    getErrors(): AuditRecord[];
    /** Get records with redacted secrets */
    getRedacted(): AuditRecord[];
    /** Clear the audit log */
    clear(): void;
    /** Get current size */
    get size(): number;
}
export declare function hashContent(data: unknown): string;
/** Glob-style pattern matching for tool names (* and ? supported) */
export declare function matchesToolPattern(toolName: string, pattern: string): boolean;
/**
 * Resolves tool permission from a set of rules.
 *
 * Rules are evaluated in priority order (highest first).
 * First matching rule wins. If no rules match, returns default permission.
 */
export declare class PermissionMatcher {
    private rules;
    private defaultPermission;
    /**
     * @param rules Permission rules to evaluate
     * @param defaultPermission Permission when no rules match (default: ASK)
     */
    constructor(rules?: ToolPermissionRule[], defaultPermission?: ToolPermissionLevel);
    /**
     * Resolve permission for a tool name.
     *
     * @param toolName Fully qualified tool name (e.g. "github_create_issue", "browser_click")
     * @param serverName Optional server name for server-level resolution
     * @param governanceBypass Whether governance bypass is active for this tool
     * @returns Resolved permission with matched rule info
     */
    resolve(toolName: string, serverName?: string, governanceBypass?: boolean): ResolvedToolPermission;
    /**
     * Get all matching rules for a tool name (for diagnostics).
     */
    getMatchingRules(toolName: string): ToolPermissionRule[];
    /**
     * Add rules at runtime.
     */
    addRules(rules: ToolPermissionRule[]): void;
    /**
     * Replace all rules at runtime.
     */
    updateRules(rules: ToolPermissionRule[]): void;
    /**
     * Remove rules by pattern.
     */
    removeRules(patterns: string[]): void;
    /**
     * Get current rule count.
     */
    get ruleCount(): number;
    private matchRules;
}
/** Check if a tool is allowed by the governance policy */
export declare function isToolAllowed(toolName: string, policy: Pick<ToolGovernancePolicy, "allowTools" | "denyTools">): {
    allowed: boolean;
    reason?: string;
};
export declare class ToolGovernor extends EventEmitter {
    private policy;
    private auditLogger;
    constructor(policy?: Partial<ToolGovernancePolicy>);
    /** Check if a tool call is permitted */
    checkToolPermission(toolName: string): {
        allowed: boolean;
        reason?: string;
    };
    /** Check if a tool bypasses governance */
    shouldBypassGovernance(toolName: string): boolean;
    /** Process a raw tool result through the governance pipeline */
    govern(toolName: string, serverName: string, args: Record<string, unknown>, rawResult: unknown, durationMs: number): GovernedToolResult;
    /** Get the audit logger */
    getAuditLogger(): AuditLogger;
    /** Update governance policy at runtime */
    updatePolicy(update: Partial<ToolGovernancePolicy>): void;
    /** Get current policy */
    getPolicy(): ToolGovernancePolicy;
    private normalizeResult;
    private extractErrorMessage;
}
