/**
 * Policy simulator — combines counterfactual replay, policy diff, and harness sample.
 */
import { readFileSync, existsSync } from 'fs';
import { PolicyDiff } from '../agentic/policy-gen/policy-diff.js';
import { simulatePolicyCounterfactual } from '../ai/policy-counterfactual.js';
import { runGuardianBenchScorecard } from './guardian-bench.js';
function stubPolicy(yaml) {
    return {
        yaml,
        confidence: 0.7,
        summary: 'Simulated policy',
        suggestions: [],
        rationale: {},
        metadata: {
            generatedAt: new Date().toISOString(),
            generatorVersion: 'policy-simulator',
            observationWindowId: 'sim',
            totalToolsObserved: 0,
            toolsInPolicy: 0,
            toolsWithRateLimits: 0,
            toolsWithSemanticGuard: 0,
            securityRulesGenerated: 0,
        },
    };
}
export async function simulatePolicyChange(opts) {
    const counterfactual = await simulatePolicyCounterfactual({
        draftRule: opts.draftRule,
        policyPath: opts.policyPath,
        tenantId: opts.tenantId,
        windowDays: opts.windowDays,
    });
    const harnessSample = runGuardianBenchScorecard(undefined, opts.benchProfile ?? 'policy-sim');
    let policyDiffSummary;
    if (opts.generatedPolicyYaml && opts.existingPolicyYaml) {
        const differ = new PolicyDiff();
        const diff = differ.diff(stubPolicy(opts.generatedPolicyYaml), opts.existingPolicyYaml);
        policyDiffSummary = diff.summary;
    }
    else if (opts.policyPath && existsSync(opts.policyPath) && opts.generatedPolicyYaml) {
        const existing = readFileSync(opts.policyPath, 'utf-8');
        const differ = new PolicyDiff();
        policyDiffSummary = differ.diff(stubPolicy(opts.generatedPolicyYaml), existing).summary;
    }
    const combinedSummary = [
        counterfactual.summary,
        harnessSample.summary,
        policyDiffSummary ? `Policy diff: ${policyDiffSummary}` : undefined,
    ].filter(Boolean).join(' | ');
    return {
        generatedAt: new Date().toISOString(),
        counterfactual,
        harnessSample,
        policyDiffSummary,
        combinedSummary,
    };
}
//# sourceMappingURL=policy-simulator.js.map