/** * Runtime permissions simulation pipeline. * * `PermissionSimulator` wraps two `LayeredPolicyEvaluator` instances, * the *actual* (authoritative) evaluator and a *simulated* (candidate) * evaluator, and runs both in parallel for every call to `evaluate()`. * * Divergence tracking: * - Counts by tool class, command prefix, and simulation mode. * - Configurable divergence threshold for enforcement gate. * - `getDivergenceReport()` returns aggregated stats. * * Simulation modes: * - `simulation-only` , Actual decision enforced; divergence recorded for * reports without warning emission. * - `warn-on-divergence`, Actual decision enforced; divergence emits a warning. * - `enforce` , Simulated decision becomes authoritative; blocked if * divergence gate fails (rate > threshold). * * Capability gate: `permissions-simulation` (permissions.simulation) must be on to use this module. */ import { GoodVibesSdkError } from '@pellux/goodvibes-errors'; import type { DivergenceReport, PermissionSimulatorConfig, PermissionsConfig, SimulationMode, SimulationResult } from './types.js'; import { LayeredPolicyEvaluator } from './evaluator.js'; /** * PermissionSimulator, Dual-evaluator simulation pipeline for runtime permissions. * * Runs two `LayeredPolicyEvaluator` instances (actual + simulated) in parallel * and tracks divergence between their decisions. * * Usage: * ```ts * const simulator = createPermissionSimulator( * { mode: 'default', rules: currentRules }, * { mode: 'default', rules: candidateRules }, * 'warn-on-divergence', * ); * const result = simulator.evaluate('write', { path: '/tmp/out.txt' }); * if (result.diverged) { * console.warn('divergence:', result.divergenceType); * } * ``` */ export declare class PermissionSimulator { private readonly actual; private readonly simulated; private readonly simulationMode; private readonly maxDivergenceRecords; private readonly divergenceThreshold; private readonly onWarning; /** All recorded divergences, capped at `maxDivergenceRecords`. */ private records; /** Per-tool-class evaluation counts (diverged + non-diverged). */ private evalsByClass; /** Per-command-prefix evaluation counts. */ private evalsByPrefix; /** Per-mode evaluation counts. */ private evalsByMode; /** Total evaluations across all calls. */ private totalEvals; private static readonly DEFAULT_MAX_RECORDS; private static readonly DEFAULT_THRESHOLD; constructor(actualConfig: PermissionsConfig, simulatedConfig: PermissionsConfig, simulationMode: SimulationMode, config?: PermissionSimulatorConfig); /** * evaluate, Runs both evaluators and returns a `SimulationResult`. * * In `enforce` mode the call will throw `SimulationEnforcementError` if * the divergence rate exceeds the configured threshold. * * @param toolName, The tool name being evaluated. * @param args , The arguments passed to the tool. */ evaluate(toolName: string, args: Record): SimulationResult; /** * getDivergenceReport, Returns aggregated divergence statistics. * * Queryable by tool class and command prefix. Includes overall summary, * per-class, per-prefix, and per-mode breakdowns. */ getDivergenceReport(): DivergenceReport; /** * getActualEvaluator, Exposes the actual evaluator for direct inspection. */ getActualEvaluator(): LayeredPolicyEvaluator; /** * getSimulatedEvaluator, Exposes the simulated evaluator for direct inspection. */ getSimulatedEvaluator(): LayeredPolicyEvaluator; /** * getSimulationMode, Returns the active simulation mode. */ getSimulationMode(): SimulationMode; /** * isDivergenceGatePassing, Returns whether the divergence rate is within * the configured threshold. Always `true` in non-enforce modes. */ isDivergenceGatePassing(): boolean; /** * assertDivergenceGate, Throws if divergence rate exceeds threshold. * * Only called in `enforce` mode prior to evaluation. */ private assertDivergenceGate; } /** * Thrown when `enforce` mode is active and the divergence gate fails. */ export declare class SimulationEnforcementError extends GoodVibesSdkError { readonly code: 'SIMULATION_ENFORCEMENT_BLOCKED'; /** Current divergence rate (0–1). */ readonly divergenceRate: number; /** Configured divergence threshold (0–1). */ readonly threshold: number; constructor(message: string, divergenceRate: number, threshold: number); } //# sourceMappingURL=simulation.d.ts.map