"use strict";
/**
 * GovernedAgent -- Simple "front door" factory for @connexum/ai-governance.
 *
 * Instead of wiring 50+ classes together, call createGovernedAgent(config)
 * and get back a governed agent that enforces rules, logs audit trails,
 * and computes compliance scores.
 *
 * @connexum/ai-governance
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.BUILT_IN_PACKS = exports.MissingPackError = exports.PackPolicyViolation = void 0;
exports.createGovernedAgent = createGovernedAgent;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const os = __importStar(require("os"));
const index_1 = require("./adapters/index");
const index_2 = require("./packs/index");
const audit_integrity_1 = require("./audit/audit-integrity");
const event_bus_1 = require("./audit/event-bus");
const pack_evaluator_1 = require("./governance/pack-evaluator");
const soc1_1 = require("./packs/soc1");
const soc2_1 = require("./packs/soc2");
const hipaa_1 = require("./packs/hipaa");
const hitech_1 = require("./packs/hitech");
const glba_1 = require("./packs/glba");
const aba_1 = require("./packs/aba");
const ftc5_1 = require("./packs/ftc5");
const sr117_1 = require("./packs/sr117");
const part11_1 = require("./packs/part11");
const sox404_1 = require("./packs/sox404");
const bsa_aml_1 = require("./packs/bsa-aml");
const nydfs500_1 = require("./packs/nydfs500");
const cfpb_2023_03_1 = require("./packs/cfpb-2023-03");
const bipa_1 = require("./packs/bipa");
const fda_samd_1 = require("./packs/fda-samd");
const part2_1 = require("./packs/part2");
const gxp_1 = require("./packs/gxp");
const nyc_ll_144_1 = require("./packs/nyc-ll-144");
const eu_ai_liability_1 = require("./packs/eu-ai-liability");
const iso_23894_1 = require("./packs/iso-23894");
const lgpd_1 = require("./packs/lgpd");
const pipl_1 = require("./packs/pipl");
// X2 disaggregation (2026-04-24): pipeda.ts deleted -- use ca-pipeda + ca-qc-law25
const ca_pipeda_1 = require("./packs/ca-pipeda");
const ca_qc_law25_1 = require("./packs/ca-qc-law25");
const gdpr_1 = require("./packs/gdpr");
const ccpa_1 = require("./packs/ccpa");
const colorado_ai_1 = require("./packs/colorado-ai");
const pcidss_1 = require("./packs/pcidss");
const dora_1 = require("./packs/dora");
const euaiact_1 = require("./packs/euaiact");
const iso27001_1 = require("./packs/iso27001");
const nist_ai_rmf_1 = require("./packs/nist-ai-rmf");
const iso42001_1 = require("./packs/iso42001");
const mifid2_1 = require("./packs/mifid2");
const naic_mdl_1 = require("./packs/naic-mdl");
const frcp26_1 = require("./packs/frcp26");
const foia_1 = require("./packs/foia");
const lpo2024_1 = require("./packs/lpo2024");
const ferpa_1 = require("./packs/ferpa");
const fedramp_1 = require("./packs/fedramp");
const stateramp_1 = require("./packs/stateramp");
const cjis_1 = require("./packs/cjis");
const cmmc2_1 = require("./packs/cmmc2");
// Mortgage-industry packs (MORTGAGE-PACKS-01, 2026-04-22; X3 split 2026-04-24)
// respa renamed to us-respa; tila-trid split into us-trid + us-tila
const us_respa_1 = require("./packs/us-respa");
const hmda_1 = require("./packs/hmda");
const us_trid_1 = require("./packs/us-trid");
const us_tila_1 = require("./packs/us-tila");
const ecoa_1 = require("./packs/ecoa");
const fcra_1 = require("./packs/fcra");
// BATCH-01: AU packs + extended packs (P0 registry fix, 2026-04-25)
const au_act_hrpaa_1 = require("./packs/au-act-hrpaa");
const au_aiethics_framework_1 = require("./packs/au-aiethics-framework");
const au_aml_ctf_1 = require("./packs/au-aml-ctf");
const au_asic_rg_271_1 = require("./packs/au-asic-rg-271");
const au_asic_rg_274_1 = require("./packs/au-asic-rg-274");
const au_cdr_1 = require("./packs/au-cdr");
const au_cps230_1 = require("./packs/au-cps230");
const au_cps234_1 = require("./packs/au-cps234");
const au_mandatory_ai_guardrails_1 = require("./packs/au-mandatory-ai-guardrails");
const au_nsw_hripa_1 = require("./packs/au-nsw-hripa");
const au_online_safety_1 = require("./packs/au-online-safety");
const au_privacy_act_1 = require("./packs/au-privacy-act");
const au_soci_act_1 = require("./packs/au-soci-act");
const au_spam_act_1 = require("./packs/au-spam-act");
const au_tga_saimd_1 = require("./packs/au-tga-saimd");
const au_vic_hra_1 = require("./packs/au-vic-hra");
const california_ab2930_1 = require("./packs/california-ab2930");
const cms_interoperability_1 = require("./packs/cms-interoperability");
const common_rule_1 = require("./packs/common-rule");
const coppa_1 = require("./packs/coppa");
const de_bdsg_1 = require("./packs/de-bdsg");
const eu_lpp_1 = require("./packs/eu-lpp");
const eu_mdr_ivdr_1 = require("./packs/eu-mdr-ivdr");
const fca_consumer_duty_1 = require("./packs/fca-consumer-duty");
const fca_op_resilience_1 = require("./packs/fca-op-resilience");
const finra_3110_1 = require("./packs/finra-3110");
const florida_student_privacy_1 = require("./packs/florida-student-privacy");
const illinois_aivia_1 = require("./packs/illinois-aivia");
const in_dpdp_1 = require("./packs/in-dpdp");
const iso20022_1 = require("./packs/iso20022");
const iso27701_1 = require("./packs/iso27701");
const jp_appi_1 = require("./packs/jp-appi");
const kr_pipa_1 = require("./packs/kr-pipa");
const maryland_hb1202_1 = require("./packs/maryland-hb1202");
const nis2_1 = require("./packs/nis2");
const nz_privacy_1 = require("./packs/nz-privacy");
const reg_e_1 = require("./packs/reg-e");
const sg_model_ai_gov_1 = require("./packs/sg-model-ai-gov");
const tennessee_elvis_1 = require("./packs/tennessee-elvis");
const texas_hb4_1 = require("./packs/texas-hb4");
const title_ix_1 = require("./packs/title-ix");
const uk_ai_framework_1 = require("./packs/uk-ai-framework");
const uk_gdpr_1 = require("./packs/uk-gdpr");
const nhs_dspt_1 = require("./packs/nhs-dspt");
const cyber_essentials_1 = require("./packs/cyber-essentials");
const nhs_dcb0129_dcb0160_1 = require("./packs/nhs-dcb0129-dcb0160");
const mhra_samd_ukca_1 = require("./packs/mhra-samd-ukca");
const nhs_dtac_1 = require("./packs/nhs-dtac");
const caldicott_principles_1 = require("./packs/caldicott-principles");
const ncsc_caf_1 = require("./packs/ncsc-caf");
const ncsc_ai_security_1 = require("./packs/ncsc-ai-security");
const uk_equality_act_1 = require("./packs/uk-equality-act");
const uk_equality_act_ai_bias_1 = require("./packs/uk-equality-act-ai-bias");
const uk_nis_regs_1 = require("./packs/uk-nis-regs");
const uk_cma_1990_1 = require("./packs/uk-cma-1990");
const uk_future_ai_legislation_1 = require("./packs/uk-future-ai-legislation");
const uk_online_safety_act_1 = require("./packs/uk-online-safety-act");
const uk_procurement_act_1 = require("./packs/uk-procurement-act");
const cma_ai_foundation_models_1 = require("./packs/cma-ai-foundation-models");
const nhs_psirf_1 = require("./packs/nhs-psirf");
const uk_ico_open_case_1 = require("./packs/uk-ico-open-case");
const nice_esf_dht_1 = require("./packs/nice-esf-dht");
const ni_equality_1 = require("./packs/ni-equality");
const scotland_awi_1 = require("./packs/scotland-awi");
const wales_future_generations_1 = require("./packs/wales-future-generations");
const scotland_psed_1 = require("./packs/scotland-psed");
const ni_hscni_1 = require("./packs/ni-hscni");
const eu_dsa_1 = require("./packs/eu-dsa");
const eu_dma_1 = require("./packs/eu-dma");
const nist_csf_1 = require("./packs/nist-csf");
const nist_800_53_1 = require("./packs/nist-800-53");
const hitrust_csf_1 = require("./packs/hitrust-csf");
const eu_data_act_1 = require("./packs/eu-data-act");
const eu_cra_1 = require("./packs/eu-cra");
const scotland_procurement_reform_1 = require("./packs/scotland-procurement-reform");
const ni_mental_capacity_1 = require("./packs/ni-mental-capacity");
const hk_pdpo_1 = require("./packs/hk-pdpo");
const vn_pdpd_1 = require("./packs/vn-pdpd");
const th_pdpa_1 = require("./packs/th-pdpa");
const cn_dsl_csl_1 = require("./packs/cn-dsl-csl");
const us_nih_coc_1 = require("./packs/us-nih-coc");
const us_nih_dms_1 = require("./packs/us-nih-dms");
const us_nih_gds_1 = require("./packs/us-nih-gds");
const us_nih_it_security_1 = require("./packs/us-nih-it-security");
const us_fda_21cfr56_1 = require("./packs/us-fda-21cfr56");
const utah_ai_policy_1 = require("./packs/utah-ai-policy");
const do_178c_1 = require("./packs/do-178c");
const fda_21_cfr_820_1 = require("./packs/fda-21-cfr-820");
const iec_62304_1 = require("./packs/iec-62304");
const iso_26262_1 = require("./packs/iso-26262");
const iec_62443_1 = require("./packs/iec-62443");
const nist_sp_800_82_1 = require("./packs/nist-sp-800-82");
const as_9100_1 = require("./packs/as-9100");
const fda_samd_precert_1 = require("./packs/fda-samd-precert");
const iso_15189_1 = require("./packs/iso-15189");
const iso_iec_80001_1 = require("./packs/iso-iec-80001");
// ---------------------------------------------------------------------------
// PackPolicyViolation error (thrown when pack evaluator returns DENY)
// ---------------------------------------------------------------------------
/**
 * Thrown by execute() when the pack evaluator produces a DENY verdict.
 * Callers should catch this to surface a governance-blocked result.
 */
class PackPolicyViolation extends Error {
    /** Human-readable explanation from the pack evaluator. */
    packReason;
    /** IDs of packs whose rules produced the DENY verdict. */
    triggeringPackIds;
    /**
     * F-NEW-CRIT-39i-2: classifier IDs (e.g. PHI_MRN, GDPR_DOB) that
     * fired inside the triggering packs. Surfaces from
     * PackEvaluatorVerdict.triggeringClassifierIds so the gov-server
     * audit chain (CRIT-39i regulatoryViolations) can record per-
     * category breadcrumbs instead of pack-level only.
     */
    triggeringClassifierIds;
    /** F-NEW-CRIT-39j-3: true when DENY came from adapter default-deny (no rule matched). */
    defaultDenyTriggered;
    constructor(reason, triggeringPackIds, triggeringClassifierIds = [], defaultDenyTriggered = false) {
        super(`Pack policy violation: ${reason}`);
        this.name = 'PackPolicyViolation';
        this.packReason = reason;
        this.triggeringPackIds = triggeringPackIds;
        this.triggeringClassifierIds = triggeringClassifierIds;
        this.defaultDenyTriggered = defaultDenyTriggered;
    }
}
exports.PackPolicyViolation = PackPolicyViolation;
/**
 * Thrown by createGovernedAgent() when a requested pack ID is not found in
 * BUILT_IN_PACKS. Replaces the previous silent-skip behavior (Task 3 fix).
 *
 * A customer requesting a non-existent pack was silently getting zero
 * enforcement -- indistinguishable from a correctly-configured agent with
 * no restrictions. This error makes the misconfiguration immediately visible.
 *
 * Callers that want softer handling (e.g., during pack catalog migrations)
 * can catch MissingPackError at the call site.
 */
class MissingPackError extends Error {
    /** The pack ID that was not found. */
    packId;
    constructor(packId, message) {
        super(message);
        this.name = 'MissingPackError';
        this.packId = packId;
    }
}
exports.MissingPackError = MissingPackError;
// ---------------------------------------------------------------------------
// Built-in pack registry (maps string IDs to pack objects)
// ---------------------------------------------------------------------------
exports.BUILT_IN_PACKS = {
    soc1: soc1_1.SOC1_PACK,
    ssae18: soc1_1.SOC1_PACK,
    soc2: soc2_1.SOC2_PACK,
    'soc-2': soc2_1.SOC2_PACK,
    'soc2-type2': soc2_1.SOC2_PACK,
    hipaa: hipaa_1.HIPAA_PACK,
    'hipaa-security': hipaa_1.HIPAA_PACK,
    'hipaa-privacy': hipaa_1.HIPAA_PACK,
    '45-cfr-164': hipaa_1.HIPAA_PACK,
    hitech: hitech_1.HITECH_PACK,
    glba: glba_1.GLBA_PACK,
    'gramm-leach-bliley': glba_1.GLBA_PACK,
    aba: aba_1.ABA_PACK,
    'aba-model-rules': aba_1.ABA_PACK,
    'opinion-512': aba_1.ABA_PACK,
    ftc5: ftc5_1.FTC5_PACK,
    'ftc-5': ftc5_1.FTC5_PACK,
    'ftc-act-5': ftc5_1.FTC5_PACK,
    'ftc-section-5': ftc5_1.FTC5_PACK,
    'sr11-7': sr117_1.SR117_PACK,
    sr117: sr117_1.SR117_PACK,
    'sr-11-7': sr117_1.SR117_PACK,
    'model-risk': sr117_1.SR117_PACK,
    part11: part11_1.PART11_PACK,
    '21cfr11': part11_1.PART11_PACK,
    '21-cfr-part-11': part11_1.PART11_PACK,
    'fda-part-11': part11_1.PART11_PACK,
    sox404: sox404_1.SOX404_PACK,
    sox: sox404_1.SOX404_PACK,
    'sox-404': sox404_1.SOX404_PACK,
    'sarbanes-oxley': sox404_1.SOX404_PACK,
    'bsa-aml': bsa_aml_1.BSA_AML_PACK,
    bsa: bsa_aml_1.BSA_AML_PACK,
    aml: bsa_aml_1.BSA_AML_PACK,
    'bank-secrecy': bsa_aml_1.BSA_AML_PACK,
    nydfs500: nydfs500_1.NYDFS500_PACK,
    'ny-dfs-500': nydfs500_1.NYDFS500_PACK,
    '23-nycrr-500': nydfs500_1.NYDFS500_PACK,
    nydfs: nydfs500_1.NYDFS500_PACK,
    'cfpb-2023-03': cfpb_2023_03_1.CFPB_2023_03_PACK,
    cfpb: cfpb_2023_03_1.CFPB_2023_03_PACK,
    'cfpb-circular-2023-03': cfpb_2023_03_1.CFPB_2023_03_PACK,
    'adverse-action-ai': cfpb_2023_03_1.CFPB_2023_03_PACK,
    bipa: bipa_1.BIPA_PACK,
    'illinois-bipa': bipa_1.BIPA_PACK,
    'biometric-info-privacy': bipa_1.BIPA_PACK,
    'fda-samd': fda_samd_1.FDA_SAMD_PACK,
    samd: fda_samd_1.FDA_SAMD_PACK,
    'fda-ai-ml': fda_samd_1.FDA_SAMD_PACK,
    'software-as-medical-device': fda_samd_1.FDA_SAMD_PACK,
    part2: part2_1.PART2_PACK,
    '42-cfr-part-2': part2_1.PART2_PACK,
    'sud-records': part2_1.PART2_PACK,
    samhsa: part2_1.PART2_PACK,
    gxp: gxp_1.GXP_PACK,
    gmp: gxp_1.GXP_PACK,
    glp: gxp_1.GXP_PACK,
    gcp: gxp_1.GXP_PACK,
    'nyc-ll-144': nyc_ll_144_1.NYC_LL_144_PACK,
    'nyc-144': nyc_ll_144_1.NYC_LL_144_PACK,
    aedt: nyc_ll_144_1.NYC_LL_144_PACK,
    'nyc-bias-audit': nyc_ll_144_1.NYC_LL_144_PACK,
    'eu-ai-liability': eu_ai_liability_1.EU_AI_LIABILITY_PACK,
    'pld-2024': eu_ai_liability_1.EU_AI_LIABILITY_PACK,
    'product-liability-eu': eu_ai_liability_1.EU_AI_LIABILITY_PACK,
    'iso-23894': iso_23894_1.ISO_23894_PACK,
    'iso-iec-23894': iso_23894_1.ISO_23894_PACK,
    'ai-risk-guidance': iso_23894_1.ISO_23894_PACK,
    lgpd: lgpd_1.LGPD_PACK,
    'brazil-privacy': lgpd_1.LGPD_PACK,
    'lei-13709': lgpd_1.LGPD_PACK,
    pipl: pipl_1.PIPL_PACK,
    'china-privacy': pipl_1.PIPL_PACK,
    'prc-pipl': pipl_1.PIPL_PACK,
    // X2 disaggregation (2026-04-24): legacy aliases map to ca-pipeda for backward compat
    'ca-pipeda': ca_pipeda_1.CA_PIPEDA_PACK,
    'ca-qc-law25': ca_qc_law25_1.QC_LAW25_PACK,
    pipeda: ca_pipeda_1.CA_PIPEDA_PACK,
    'canada-privacy': ca_pipeda_1.CA_PIPEDA_PACK,
    'quebec-law-25': ca_qc_law25_1.QC_LAW25_PACK,
    'pipeda-law25': ca_pipeda_1.CA_PIPEDA_PACK,
    gdpr: gdpr_1.GDPR_PACK,
    'gdpr-eu': gdpr_1.GDPR_PACK,
    'eu-gdpr': gdpr_1.GDPR_PACK,
    '2016/679': gdpr_1.GDPR_PACK,
    ccpa: ccpa_1.CCPA_PACK,
    cpra: ccpa_1.CCPA_PACK,
    'ccpa-cpra': ccpa_1.CCPA_PACK,
    'colorado-ai': colorado_ai_1.COLORADO_AI_PACK,
    coai: colorado_ai_1.COLORADO_AI_PACK,
    'sb-24-205': colorado_ai_1.COLORADO_AI_PACK,
    pcidss: pcidss_1.PCIDSS_PACK,
    'pci-dss': pcidss_1.PCIDSS_PACK,
    'pci-dss-4': pcidss_1.PCIDSS_PACK,
    'pci-dss-v4': pcidss_1.PCIDSS_PACK,
    dora: dora_1.DORA_PACK,
    'dora-eu': dora_1.DORA_PACK,
    'regulation-2022-2554': dora_1.DORA_PACK,
    'digital-operational-resilience': dora_1.DORA_PACK,
    euaiact: euaiact_1.EUAIACT_PACK,
    'eu-ai-act': euaiact_1.EUAIACT_PACK,
    'regulation-2024-1689': euaiact_1.EUAIACT_PACK,
    'ai-act': euaiact_1.EUAIACT_PACK,
    iso27001: iso27001_1.ISO27001_PACK,
    'iso-27001': iso27001_1.ISO27001_PACK,
    'iso-iec-27001': iso27001_1.ISO27001_PACK,
    'iso27001-2022': iso27001_1.ISO27001_PACK,
    nist_ai_rmf: nist_ai_rmf_1.NIST_AI_RMF_PACK,
    nistairmf: nist_ai_rmf_1.NIST_AI_RMF_PACK,
    'nist-ai-rmf': nist_ai_rmf_1.NIST_AI_RMF_PACK,
    'nist-ai-100-1': nist_ai_rmf_1.NIST_AI_RMF_PACK,
    iso_42001: iso42001_1.ISO_42001_PACK,
    iso42001: iso42001_1.ISO_42001_PACK,
    'iso-42001': iso42001_1.ISO_42001_PACK,
    'iso-iec-42001': iso42001_1.ISO_42001_PACK,
    'iso-42001-2023': iso42001_1.ISO_42001_PACK,
    aims: iso42001_1.ISO_42001_PACK,
    mifid2: mifid2_1.MIFID2_PACK,
    mifid: mifid2_1.MIFID2_PACK,
    'mifid-ii': mifid2_1.MIFID2_PACK,
    'markets-in-financial-instruments': mifid2_1.MIFID2_PACK,
    'naic-mdl': naic_mdl_1.NAIC_MDL_PACK,
    'naic-mdl-668': naic_mdl_1.NAIC_MDL_PACK,
    'insurance-data-security': naic_mdl_1.NAIC_MDL_PACK,
    naic: naic_mdl_1.NAIC_MDL_PACK,
    frcp26: frcp26_1.FRCP26_PACK,
    'frcp-26': frcp26_1.FRCP26_PACK,
    'federal-rules-civil-procedure-26': frcp26_1.FRCP26_PACK,
    ediscovery: frcp26_1.FRCP26_PACK,
    foia: foia_1.FOIA_PACK,
    '5-usc-552': foia_1.FOIA_PACK,
    'freedom-of-information': foia_1.FOIA_PACK,
    lpo2024: lpo2024_1.LPO2024_PACK,
    'lpo-2024': lpo2024_1.LPO2024_PACK,
    'legal-practitioner-ai-disclosure': lpo2024_1.LPO2024_PACK,
    // F-PACK-CLEANUP-1 (2026-05-08): appi.ts deleted as duplicate of jp-appi.ts;
    // these aliases now resolve to the canonical JP_APPI_PACK.
    appi: jp_appi_1.JP_APPI_PACK,
    'appi-japan': jp_appi_1.JP_APPI_PACK,
    'japan-privacy': jp_appi_1.JP_APPI_PACK,
    ferpa: ferpa_1.FERPA_PACK,
    'family-educational-rights-privacy': ferpa_1.FERPA_PACK,
    'student-privacy': ferpa_1.FERPA_PACK,
    fedramp: fedramp_1.FEDRAMP_PACK,
    'fed-ramp': fedramp_1.FEDRAMP_PACK,
    'fedramp-moderate': fedramp_1.FEDRAMP_PACK,
    stateramp: stateramp_1.STATERAMP_PACK,
    'state-ramp': stateramp_1.STATERAMP_PACK,
    cjis: cjis_1.CJIS_PACK,
    'cjis-security-policy': cjis_1.CJIS_PACK,
    'fbi-cjis': cjis_1.CJIS_PACK,
    cmmc2: cmmc2_1.CMMC2_PACK,
    cmmc: cmmc2_1.CMMC2_PACK,
    'cmmc-2': cmmc2_1.CMMC2_PACK,
    'cmmc-level-2': cmmc2_1.CMMC2_PACK,
    'nist-800-171': cmmc2_1.CMMC2_PACK,
    // Mortgage-industry packs (MORTGAGE-PACKS-01, 2026-04-22)
    // X3 2026-04-24: respa renamed to us-respa; tila-trid split into us-trid + us-tila
    'us-respa': us_respa_1.US_RESPA_PACK,
    respa: us_respa_1.US_RESPA_PACK, // backward-compat alias
    'regulation-x': us_respa_1.US_RESPA_PACK,
    '12-usc-2601': us_respa_1.US_RESPA_PACK,
    '12-cfr-1024': us_respa_1.US_RESPA_PACK,
    hmda: hmda_1.HMDA_PACK,
    'regulation-c': hmda_1.HMDA_PACK,
    '12-usc-2801': hmda_1.HMDA_PACK,
    '12-cfr-1003': hmda_1.HMDA_PACK,
    'us-trid': us_trid_1.US_TRID_PACK,
    trid: us_trid_1.US_TRID_PACK, // backward-compat alias
    'tila-trid': us_trid_1.US_TRID_PACK, // backward-compat alias -- routes to TRID pack
    'us-tila': us_tila_1.US_TILA_PACK,
    tila: us_tila_1.US_TILA_PACK, // backward-compat alias
    'regulation-z': us_tila_1.US_TILA_PACK,
    '12-cfr-1026': us_tila_1.US_TILA_PACK,
    '15-usc-1601': us_tila_1.US_TILA_PACK,
    ecoa: ecoa_1.ECOA_PACK,
    'regulation-b': ecoa_1.ECOA_PACK,
    '15-usc-1691': ecoa_1.ECOA_PACK,
    '12-cfr-1002': ecoa_1.ECOA_PACK,
    'equal-credit-opportunity': ecoa_1.ECOA_PACK,
    fcra: fcra_1.FCRA_PACK,
    'fair-credit-reporting': fcra_1.FCRA_PACK,
    '15-usc-1681': fcra_1.FCRA_PACK,
    'consumer-report': fcra_1.FCRA_PACK,
    // -------------------------------------------------------------------------
    // BATCH-01: 48 previously-unreachable packs (P0 registry fix, 2026-04-25)
    // -------------------------------------------------------------------------
    // AU state health privacy (X1-disaggregation, 2026-04-24)
    'au-act-hrpaa': au_act_hrpaa_1.AU_ACT_HRPAA_PACK,
    'act-hrpaa': au_act_hrpaa_1.AU_ACT_HRPAA_PACK,
    'au-health-act-hrpaa': au_act_hrpaa_1.AU_ACT_HRPAA_PACK,
    // AU AI Ethics Framework + Voluntary AI Safety Standard
    'au-aiethics-framework': au_aiethics_framework_1.AU_AIETHICS_PACK,
    'au-ai-ethics': au_aiethics_framework_1.AU_AIETHICS_PACK,
    'au-voluntary-ai-safety': au_aiethics_framework_1.AU_AIETHICS_PACK,
    'disr-ai-ethics': au_aiethics_framework_1.AU_AIETHICS_PACK,
    // AU AML/CTF
    'au-aml-ctf': au_aml_ctf_1.AU_AML_CTF_PACK,
    'au-aml': au_aml_ctf_1.AU_AML_CTF_PACK,
    'austrac-aml': au_aml_ctf_1.AU_AML_CTF_PACK,
    // AU ASIC RG 271
    'au-asic-rg-271': au_asic_rg_271_1.AU_ASIC_RG271_PACK,
    'au-asic-rg271': au_asic_rg_271_1.AU_ASIC_RG271_PACK,
    'asic-rg-271': au_asic_rg_271_1.AU_ASIC_RG271_PACK,
    // AU ASIC RG 274
    'au-asic-rg-274': au_asic_rg_274_1.AU_ASIC_RG274_PACK,
    'au-asic-rg274': au_asic_rg_274_1.AU_ASIC_RG274_PACK,
    'asic-rg-274': au_asic_rg_274_1.AU_ASIC_RG274_PACK,
    // AU CDR (Consumer Data Right)
    'au-cdr': au_cdr_1.AU_CDR_PACK,
    'au-consumer-data-right': au_cdr_1.AU_CDR_PACK,
    'cdr-au': au_cdr_1.AU_CDR_PACK,
    // AU CPS 230
    'au-cps230': au_cps230_1.AU_CPS230_PACK,
    'apra-cps-230': au_cps230_1.AU_CPS230_PACK,
    'cps-230': au_cps230_1.AU_CPS230_PACK,
    // AU CPS 234
    'au-cps234': au_cps234_1.AU_CPS234_PACK,
    'apra-cps-234': au_cps234_1.AU_CPS234_PACK,
    'cps-234': au_cps234_1.AU_CPS234_PACK,
    // AU Mandatory AI Guardrails
    'au-mandatory-ai-guardrails': au_mandatory_ai_guardrails_1.AU_MANDATORY_AI_GUARDRAILS_PACK,
    'au-mandatory-guardrails': au_mandatory_ai_guardrails_1.AU_MANDATORY_AI_GUARDRAILS_PACK,
    'disr-mandatory-ai-guardrails': au_mandatory_ai_guardrails_1.AU_MANDATORY_AI_GUARDRAILS_PACK,
    // AU NSW Health Records (HRIPA)
    'au-nsw-hripa': au_nsw_hripa_1.AU_NSW_HRIPA_PACK,
    'nsw-hripa': au_nsw_hripa_1.AU_NSW_HRIPA_PACK,
    'au-nsw-health-records': au_nsw_hripa_1.AU_NSW_HRIPA_PACK,
    // AU Online Safety Act
    'au-online-safety': au_online_safety_1.AU_ONLINE_SAFETY_PACK,
    'au-online-safety-act': au_online_safety_1.AU_ONLINE_SAFETY_PACK,
    'osa-au': au_online_safety_1.AU_ONLINE_SAFETY_PACK,
    // AU Privacy Act 1988
    'au-privacy-act': au_privacy_act_1.AU_PRIVACY_ACT_PACK,
    'au-privacy-act-1988': au_privacy_act_1.AU_PRIVACY_ACT_PACK,
    'oaic-privacy': au_privacy_act_1.AU_PRIVACY_ACT_PACK,
    // AU SOCI Act
    'au-soci-act': au_soci_act_1.AU_SOCI_PACK,
    'au-soci': au_soci_act_1.AU_SOCI_PACK,
    'soci-act-au': au_soci_act_1.AU_SOCI_PACK,
    // AU Spam Act 2003
    'au-spam-act': au_spam_act_1.AU_SPAM_ACT_PACK,
    'au-spam-act-2003': au_spam_act_1.AU_SPAM_ACT_PACK,
    'spam-act-au': au_spam_act_1.AU_SPAM_ACT_PACK,
    // AU TGA SaMD
    'au-tga-saimd': au_tga_saimd_1.AU_TGA_SAIMD_PACK,
    'au-tga-samd': au_tga_saimd_1.AU_TGA_SAIMD_PACK,
    'tga-saimd': au_tga_saimd_1.AU_TGA_SAIMD_PACK,
    // AU VIC Health Records Act
    'au-vic-hra': au_vic_hra_1.AU_VIC_HRA_PACK,
    'vic-hra': au_vic_hra_1.AU_VIC_HRA_PACK,
    'au-vic-health-records': au_vic_hra_1.AU_VIC_HRA_PACK,
    // California AB 2930 (employment AI)
    'california-ab2930': california_ab2930_1.CALIFORNIA_AB2930_PACK,
    'ca-ab-2930': california_ab2930_1.CALIFORNIA_AB2930_PACK,
    'ab-2930': california_ab2930_1.CALIFORNIA_AB2930_PACK,
    'california-employment-ai': california_ab2930_1.CALIFORNIA_AB2930_PACK,
    // CMS Interoperability
    'cms-interoperability': cms_interoperability_1.CMS_INTEROPERABILITY_PACK,
    'cms-interop': cms_interoperability_1.CMS_INTEROPERABILITY_PACK,
    '45-cfr-170': cms_interoperability_1.CMS_INTEROPERABILITY_PACK,
    // Common Rule (45 CFR Part 46)
    'common-rule': common_rule_1.COMMON_RULE_PACK,
    '45-cfr-46': common_rule_1.COMMON_RULE_PACK,
    'belmont-report': common_rule_1.COMMON_RULE_PACK,
    'human-subjects-research': common_rule_1.COMMON_RULE_PACK,
    // COPPA
    'coppa': coppa_1.COPPA_PACK,
    'childrens-online-privacy': coppa_1.COPPA_PACK,
    '16-cfr-312': coppa_1.COPPA_PACK,
    // DE BDSG (German Federal Data Protection Act)
    'de-bdsg': de_bdsg_1.DE_BDSG_PACK,
    'bdsg': de_bdsg_1.DE_BDSG_PACK,
    'german-data-protection': de_bdsg_1.DE_BDSG_PACK,
    // EU Legal Professional Privilege
    'eu-lpp': eu_lpp_1.EU_LPP_PACK,
    'eu-legal-privilege': eu_lpp_1.EU_LPP_PACK,
    'legal-professional-privilege': eu_lpp_1.EU_LPP_PACK,
    // EU MDR/IVDR (Medical Device Regulation)
    'eu-mdr-ivdr': eu_mdr_ivdr_1.EU_MDR_IVDR_PACK,
    'eu-mdr': eu_mdr_ivdr_1.EU_MDR_IVDR_PACK,
    'eu-ivdr': eu_mdr_ivdr_1.EU_MDR_IVDR_PACK,
    'regulation-2017-745': eu_mdr_ivdr_1.EU_MDR_IVDR_PACK,
    // FCA Consumer Duty
    'fca-consumer-duty': fca_consumer_duty_1.FCA_CONSUMER_DUTY_PACK,
    'uk-fca-consumer-duty': fca_consumer_duty_1.FCA_CONSUMER_DUTY_PACK,
    'ps22-9': fca_consumer_duty_1.FCA_CONSUMER_DUTY_PACK,
    // FCA Operational Resilience
    'fca-op-resilience': fca_op_resilience_1.FCA_OP_RESILIENCE_PACK,
    'fca-operational-resilience': fca_op_resilience_1.FCA_OP_RESILIENCE_PACK,
    'ps21-3': fca_op_resilience_1.FCA_OP_RESILIENCE_PACK,
    // FINRA 3110 (Supervision)
    'finra-3110': finra_3110_1.FINRA_3110_PACK,
    'finra': finra_3110_1.FINRA_3110_PACK,
    'finra-supervision': finra_3110_1.FINRA_3110_PACK,
    'wsp': finra_3110_1.FINRA_3110_PACK,
    // Florida Student Privacy
    'florida-student-privacy': florida_student_privacy_1.FLORIDA_STUDENT_PRIVACY_PACK,
    'fl-student-privacy': florida_student_privacy_1.FLORIDA_STUDENT_PRIVACY_PACK,
    'florida-cspa': florida_student_privacy_1.FLORIDA_STUDENT_PRIVACY_PACK,
    // Illinois AIVIA (video interview AI)
    'illinois-aivia': illinois_aivia_1.ILLINOIS_AIVIA_PACK,
    'aivia': illinois_aivia_1.ILLINOIS_AIVIA_PACK,
    'il-aivia': illinois_aivia_1.ILLINOIS_AIVIA_PACK,
    'illinois-ai-video-interview': illinois_aivia_1.ILLINOIS_AIVIA_PACK,
    // India DPDP Act
    'in-dpdp': in_dpdp_1.IN_DPDP_PACK,
    'india-dpdp': in_dpdp_1.IN_DPDP_PACK,
    'dpdp': in_dpdp_1.IN_DPDP_PACK,
    'india-data-protection': in_dpdp_1.IN_DPDP_PACK,
    // ISO 20022 (financial messaging)
    'iso20022': iso20022_1.ISO20022_PACK,
    'iso-20022': iso20022_1.ISO20022_PACK,
    'iso-iec-20022': iso20022_1.ISO20022_PACK,
    // ISO 27701 (privacy extension to 27001)
    'iso27701': iso27701_1.ISO27701_PACK,
    'iso-27701': iso27701_1.ISO27701_PACK,
    'iso-iec-27701': iso27701_1.ISO27701_PACK,
    'pims': iso27701_1.ISO27701_PACK,
    // JP APPI
    'jp-appi': jp_appi_1.JP_APPI_PACK,
    'japan-appi': jp_appi_1.JP_APPI_PACK,
    'appi-2022': jp_appi_1.JP_APPI_PACK,
    // KR PIPA
    'kr-pipa': kr_pipa_1.KR_PIPA_PACK,
    'korea-pipa': kr_pipa_1.KR_PIPA_PACK,
    'pipa-kr': kr_pipa_1.KR_PIPA_PACK,
    // Maryland HB 1202 (employment AI)
    'maryland-hb1202': maryland_hb1202_1.MARYLAND_HB1202_PACK,
    'md-hb-1202': maryland_hb1202_1.MARYLAND_HB1202_PACK,
    'maryland-ai-employment': maryland_hb1202_1.MARYLAND_HB1202_PACK,
    // EU NIS 2
    'nis2': nis2_1.NIS2_PACK,
    'eu-nis2': nis2_1.NIS2_PACK,
    'nis-2': nis2_1.NIS2_PACK,
    'network-information-security-2': nis2_1.NIS2_PACK,
    // NZ Privacy Act 2020
    'nz-privacy': nz_privacy_1.NZ_PRIVACY_PACK,
    'nz-privacy-act-2020': nz_privacy_1.NZ_PRIVACY_PACK,
    'privacy-act-nz': nz_privacy_1.NZ_PRIVACY_PACK,
    // Regulation E (electronic fund transfers)
    'reg-e': reg_e_1.REG_E_PACK,
    'regulation-e': reg_e_1.REG_E_PACK,
    '12-cfr-1005': reg_e_1.REG_E_PACK,
    'efta': reg_e_1.REG_E_PACK,
    // SG Model AI Governance Framework
    'sg-model-ai-gov': sg_model_ai_gov_1.SG_MODEL_AI_GOV_PACK,
    'singapore-ai-governance': sg_model_ai_gov_1.SG_MODEL_AI_GOV_PACK,
    'sg-pdpc-ai': sg_model_ai_gov_1.SG_MODEL_AI_GOV_PACK,
    // Tennessee ELVIS Act (AI + likeness)
    'tennessee-elvis': tennessee_elvis_1.TENNESSEE_ELVIS_PACK,
    'elvis-act': tennessee_elvis_1.TENNESSEE_ELVIS_PACK,
    'tn-elvis': tennessee_elvis_1.TENNESSEE_ELVIS_PACK,
    'tennessee-ai-likeness': tennessee_elvis_1.TENNESSEE_ELVIS_PACK,
    // Texas HB 4 (consumer AI data)
    'texas-hb4': texas_hb4_1.TEXAS_HB4_PACK,
    'tx-hb-4': texas_hb4_1.TEXAS_HB4_PACK,
    'texas-consumer-ai': texas_hb4_1.TEXAS_HB4_PACK,
    // Title IX (sex discrimination)
    'title-ix': title_ix_1.TITLE_IX_PACK,
    'title-9': title_ix_1.TITLE_IX_PACK,
    '34-cfr-106': title_ix_1.TITLE_IX_PACK,
    'title-ix-education': title_ix_1.TITLE_IX_PACK,
    // UK AI Framework
    'uk-ai-framework': uk_ai_framework_1.UK_AI_FRAMEWORK_PACK,
    'uk-ai-strategy': uk_ai_framework_1.UK_AI_FRAMEWORK_PACK,
    'dsit-ai-framework': uk_ai_framework_1.UK_AI_FRAMEWORK_PACK,
    // UK GDPR
    'uk-gdpr': uk_gdpr_1.UK_GDPR_PACK,
    'uk-data-protection-act': uk_gdpr_1.UK_GDPR_PACK,
    'dpa-2018': uk_gdpr_1.UK_GDPR_PACK,
    // NHS DSPT (Wave 1 Pack 5 — F-NEW-TIER-10-UK-WAVE1-ROADMAP)
    'nhs-dspt': nhs_dspt_1.NHS_DSPT_PACK,
    'nhs-data-security-protection-toolkit': nhs_dspt_1.NHS_DSPT_PACK,
    'dspt': nhs_dspt_1.NHS_DSPT_PACK,
    // Cyber Essentials / CE+ (Wave 1 Pack 6 — F-NEW-TIER-10-UK-WAVE1-ROADMAP)
    'cyber-essentials': cyber_essentials_1.CYBER_ESSENTIALS_PACK,
    'cyber-essentials-plus': cyber_essentials_1.CYBER_ESSENTIALS_PACK,
    'ce': cyber_essentials_1.CYBER_ESSENTIALS_PACK,
    'ce-plus': cyber_essentials_1.CYBER_ESSENTIALS_PACK,
    'ncsc-ce': cyber_essentials_1.CYBER_ESSENTIALS_PACK,
    // NHS Clinical Safety DCB0129 + DCB0160 (Wave 1 Pack 7 — F-NEW-TIER-10-UK-WAVE1-ROADMAP)
    'nhs-clinical-safety': nhs_dcb0129_dcb0160_1.NHS_CLINICAL_SAFETY_PACK,
    'dcb0129': nhs_dcb0129_dcb0160_1.NHS_CLINICAL_SAFETY_PACK,
    'dcb0160': nhs_dcb0129_dcb0160_1.NHS_CLINICAL_SAFETY_PACK,
    'dcb-0129': nhs_dcb0129_dcb0160_1.NHS_CLINICAL_SAFETY_PACK,
    'dcb-0160': nhs_dcb0129_dcb0160_1.NHS_CLINICAL_SAFETY_PACK,
    'nhs-dcb0129-dcb0160': nhs_dcb0129_dcb0160_1.NHS_CLINICAL_SAFETY_PACK,
    'clinical-safety-case': nhs_dcb0129_dcb0160_1.NHS_CLINICAL_SAFETY_PACK,
    'cscr': nhs_dcb0129_dcb0160_1.NHS_CLINICAL_SAFETY_PACK,
    'nhs-clinical-risk-management': nhs_dcb0129_dcb0160_1.NHS_CLINICAL_SAFETY_PACK,
    // MHRA SaMD / UKCA (Wave 1 Pack 4 — F-NEW-TIER-10-UK-WAVE1-ROADMAP)
    'mhra-samd-ukca': mhra_samd_ukca_1.MHRA_SAMD_UKCA_PACK,
    'mhra-samd': mhra_samd_ukca_1.MHRA_SAMD_UKCA_PACK,
    'uk-samd': mhra_samd_ukca_1.MHRA_SAMD_UKCA_PACK,
    'ukca-medical-device': mhra_samd_ukca_1.MHRA_SAMD_UKCA_PACK,
    'mhra-ai-as-medical-device': mhra_samd_ukca_1.MHRA_SAMD_UKCA_PACK,
    'mhra-aimd': mhra_samd_ukca_1.MHRA_SAMD_UKCA_PACK,
    'uk-mdr-2002': mhra_samd_ukca_1.MHRA_SAMD_UKCA_PACK,
    // NHS Innovation Service / DTAC composite (Wave 1 Pack 2 — F-NEW-TIER-10-UK-WAVE1-ROADMAP)
    'nhs-dtac': nhs_dtac_1.NHS_DTAC_PACK,
    'dtac': nhs_dtac_1.NHS_DTAC_PACK,
    'nhs-innovation-service': nhs_dtac_1.NHS_DTAC_PACK,
    'nhs-innovation-service-dtac': nhs_dtac_1.NHS_DTAC_PACK,
    'digital-technology-assessment-criteria': nhs_dtac_1.NHS_DTAC_PACK,
    // Caldicott Principles 2020 (Wave 2 — DTAC composite drops transitional flag when this pack is registered)
    'caldicott-principles': caldicott_principles_1.CALDICOTT_PRINCIPLES_PACK,
    'caldicott': caldicott_principles_1.CALDICOTT_PRINCIPLES_PACK,
    'caldicott-principles-2020': caldicott_principles_1.CALDICOTT_PRINCIPLES_PACK,
    'caldicott-guardian': caldicott_principles_1.CALDICOTT_PRINCIPLES_PACK,
    'ndg-caldicott': caldicott_principles_1.CALDICOTT_PRINCIPLES_PACK,
    'uk-caldicott': caldicott_principles_1.CALDICOTT_PRINCIPLES_PACK,
    // NCSC Cyber Assessment Framework (CAF) — UK 16-pack item #8
    'ncsc-caf': ncsc_caf_1.NCSC_CAF_PACK,
    'caf': ncsc_caf_1.NCSC_CAF_PACK,
    'ncsc-cyber-assessment-framework': ncsc_caf_1.NCSC_CAF_PACK,
    'cyber-assessment-framework': ncsc_caf_1.NCSC_CAF_PACK,
    'govassure': ncsc_caf_1.NCSC_CAF_PACK,
    'caf-v3': ncsc_caf_1.NCSC_CAF_PACK,
    // NCSC Guidelines for Secure AI System Development (2024) — TIER 10-UK Wave 2
    'ncsc-ai-security': ncsc_ai_security_1.NCSC_AI_SECURITY_PACK,
    'ncsc-ai-security-guidelines': ncsc_ai_security_1.NCSC_AI_SECURITY_PACK,
    'ncsc-secure-ai': ncsc_ai_security_1.NCSC_AI_SECURITY_PACK,
    'ncsc-ai-guidelines-2024': ncsc_ai_security_1.NCSC_AI_SECURITY_PACK,
    'secure-ai-system-development': ncsc_ai_security_1.NCSC_AI_SECURITY_PACK,
    'cisa-ncsc-ai-security': ncsc_ai_security_1.NCSC_AI_SECURITY_PACK,
    'joint-guidelines-ai-security': ncsc_ai_security_1.NCSC_AI_SECURITY_PACK,
    // UK Equality Act 2010 — UK 16-pack item #11
    'uk-equality-act': uk_equality_act_1.UK_EQUALITY_ACT_PACK,
    'equality-act': uk_equality_act_1.UK_EQUALITY_ACT_PACK,
    'equality-act-2010': uk_equality_act_1.UK_EQUALITY_ACT_PACK,
    'uk-equality-act-2010': uk_equality_act_1.UK_EQUALITY_ACT_PACK,
    'ehrc': uk_equality_act_1.UK_EQUALITY_ACT_PACK,
    'psed': uk_equality_act_1.UK_EQUALITY_ACT_PACK,
    'public-sector-equality-duty': uk_equality_act_1.UK_EQUALITY_ACT_PACK,
    // UK Equality Act 2010 + ICO-EHRC Joint AI Bias Guidance — Section D.2 TIER 10-UK Wave 2
    'uk-equality-act-ai-bias': uk_equality_act_ai_bias_1.UK_EQUALITY_ACT_AI_BIAS_PACK,
    'equality-act-ai-bias': uk_equality_act_ai_bias_1.UK_EQUALITY_ACT_AI_BIAS_PACK,
    'ico-ehrc-ai-bias': uk_equality_act_ai_bias_1.UK_EQUALITY_ACT_AI_BIAS_PACK,
    'ehrc-ai-guidance': uk_equality_act_ai_bias_1.UK_EQUALITY_ACT_AI_BIAS_PACK,
    'uk-ai-equality': uk_equality_act_ai_bias_1.UK_EQUALITY_ACT_AI_BIAS_PACK,
    // UK NIS Regulations 2018 — UK 16-pack item #12
    'uk-nis-regs': uk_nis_regs_1.UK_NIS_REGS_PACK,
    'uk-nis': uk_nis_regs_1.UK_NIS_REGS_PACK,
    'uk-nis-regulations': uk_nis_regs_1.UK_NIS_REGS_PACK,
    'uk-nis-regulations-2018': uk_nis_regs_1.UK_NIS_REGS_PACK,
    'nis-uk': uk_nis_regs_1.UK_NIS_REGS_PACK,
    'si-2018-506': uk_nis_regs_1.UK_NIS_REGS_PACK,
    // UK Computer Misuse Act 1990 — UK 16-pack item #17 (Tier 10-UK)
    'uk-cma-1990': uk_cma_1990_1.UK_CMA_1990_PACK,
    'uk-cma': uk_cma_1990_1.UK_CMA_1990_PACK,
    'cma-1990': uk_cma_1990_1.UK_CMA_1990_PACK,
    'computer-misuse-act': uk_cma_1990_1.UK_CMA_1990_PACK,
    'computer-misuse-act-1990': uk_cma_1990_1.UK_CMA_1990_PACK,
    'uk-computer-misuse-act': uk_cma_1990_1.UK_CMA_1990_PACK,
    'uk-c18-1990': uk_cma_1990_1.UK_CMA_1990_PACK,
    // UK Future AI Legislation Horizon-Scan — UK 16-pack item #16 (last)
    'uk-future-ai-legislation': uk_future_ai_legislation_1.UK_FUTURE_AI_LEGISLATION_PACK,
    'uk-ai-horizon': uk_future_ai_legislation_1.UK_FUTURE_AI_LEGISLATION_PACK,
    'uk-future-ai': uk_future_ai_legislation_1.UK_FUTURE_AI_LEGISLATION_PACK,
    'uk-ai-bill': uk_future_ai_legislation_1.UK_FUTURE_AI_LEGISLATION_PACK,
    'dsit-ai-bill': uk_future_ai_legislation_1.UK_FUTURE_AI_LEGISLATION_PACK,
    // UK Online Safety Act 2023 — UK 16-pack item #13
    'uk-online-safety-act': uk_online_safety_act_1.UK_ONLINE_SAFETY_PACK,
    'online-safety-act': uk_online_safety_act_1.UK_ONLINE_SAFETY_PACK,
    'online-safety-act-2023': uk_online_safety_act_1.UK_ONLINE_SAFETY_PACK,
    'osa': uk_online_safety_act_1.UK_ONLINE_SAFETY_PACK,
    'ofcom-osa': uk_online_safety_act_1.UK_ONLINE_SAFETY_PACK,
    'uk-osa': uk_online_safety_act_1.UK_ONLINE_SAFETY_PACK,
    // UK Procurement Act 2023 — UK 16-pack item #14
    'uk-procurement-act': uk_procurement_act_1.UK_PROCUREMENT_PACK,
    'procurement-act': uk_procurement_act_1.UK_PROCUREMENT_PACK,
    'procurement-act-2023': uk_procurement_act_1.UK_PROCUREMENT_PACK,
    'uk-procurement-act-2023': uk_procurement_act_1.UK_PROCUREMENT_PACK,
    'pa-2023': uk_procurement_act_1.UK_PROCUREMENT_PACK,
    'procurement-review-unit': uk_procurement_act_1.UK_PROCUREMENT_PACK,
    'pru': uk_procurement_act_1.UK_PROCUREMENT_PACK,
    // CMA AI Foundation Models + DMCC Act 2024 — UK 16-pack item #15
    'cma-ai-foundation-models': cma_ai_foundation_models_1.CMA_AI_FM_PACK,
    'cma-ai-fm': cma_ai_foundation_models_1.CMA_AI_FM_PACK,
    'cma-ai': cma_ai_foundation_models_1.CMA_AI_FM_PACK,
    'cma-foundation-models': cma_ai_foundation_models_1.CMA_AI_FM_PACK,
    'uk-cma-ai': cma_ai_foundation_models_1.CMA_AI_FM_PACK,
    'dmcc-act': cma_ai_foundation_models_1.CMA_AI_FM_PACK,
    'digital-markets-competition-consumers-act': cma_ai_foundation_models_1.CMA_AI_FM_PACK,
    'sms-designation': cma_ai_foundation_models_1.CMA_AI_FM_PACK,
    'dmu': cma_ai_foundation_models_1.CMA_AI_FM_PACK,
    // NHS PSIRF (Patient Safety Incident Response Framework) — UK 16-pack item #2 (NHS slot)
    'nhs-psirf': nhs_psirf_1.NHS_PSIRF_PACK,
    'psirf': nhs_psirf_1.NHS_PSIRF_PACK,
    'psirp': nhs_psirf_1.NHS_PSIRF_PACK,
    'psirs': nhs_psirf_1.NHS_PSIRF_PACK,
    'nhs-patient-safety-incident-response-framework': nhs_psirf_1.NHS_PSIRF_PACK,
    'patient-safety-incident-response-framework': nhs_psirf_1.NHS_PSIRF_PACK,
    'nhs-incident-response': nhs_psirf_1.NHS_PSIRF_PACK,
    // UK ICO Open Case (legal-hold posture) — UK 16-pack item #1
    'uk-ico-open-case': uk_ico_open_case_1.UK_ICO_OPEN_CASE_PACK,
    'uk-ico': uk_ico_open_case_1.UK_ICO_OPEN_CASE_PACK,
    'ico-open-case': uk_ico_open_case_1.UK_ICO_OPEN_CASE_PACK,
    'ico-investigation': uk_ico_open_case_1.UK_ICO_OPEN_CASE_PACK,
    'ico-legal-hold': uk_ico_open_case_1.UK_ICO_OPEN_CASE_PACK,
    'ico-enforcement': uk_ico_open_case_1.UK_ICO_OPEN_CASE_PACK,
    // NICE ESF for Digital Health Technologies — UK 16-pack item #3 (TGA slot, UK has no TGA equivalent)
    'nice-esf-dht': nice_esf_dht_1.NICE_ESF_DHT_PACK,
    'nice-esf': nice_esf_dht_1.NICE_ESF_DHT_PACK,
    'nice-evidence-standards-framework': nice_esf_dht_1.NICE_ESF_DHT_PACK,
    'nice-dht': nice_esf_dht_1.NICE_ESF_DHT_PACK,
    'esf-dht': nice_esf_dht_1.NICE_ESF_DHT_PACK,
    'nice-digital-health': nice_esf_dht_1.NICE_ESF_DHT_PACK,
    'uk-hta-dht': nice_esf_dht_1.NICE_ESF_DHT_PACK,
    // Northern Ireland Equality (s.75 NI Act 1998 + Equality NI Orders + FETO) — devolved-substantive #1
    'ni-equality': ni_equality_1.NI_EQUALITY_PACK,
    'ni-equality-act': ni_equality_1.NI_EQUALITY_PACK,
    'northern-ireland-equality': ni_equality_1.NI_EQUALITY_PACK,
    'section-75': ni_equality_1.NI_EQUALITY_PACK,
    's75-ni': ni_equality_1.NI_EQUALITY_PACK,
    'ni-s75': ni_equality_1.NI_EQUALITY_PACK,
    'feto': ni_equality_1.NI_EQUALITY_PACK,
    'fair-employment-treatment-ni': ni_equality_1.NI_EQUALITY_PACK,
    'ecni': ni_equality_1.NI_EQUALITY_PACK,
    // Adults with Incapacity (Scotland) Act 2000 — devolved-substantive #2
    'scotland-awi': scotland_awi_1.SCOTLAND_AWI_PACK,
    'scotland-awi-act': scotland_awi_1.SCOTLAND_AWI_PACK,
    'awi-scotland': scotland_awi_1.SCOTLAND_AWI_PACK,
    'adults-with-incapacity-scotland': scotland_awi_1.SCOTLAND_AWI_PACK,
    'awi-2000': scotland_awi_1.SCOTLAND_AWI_PACK,
    // Wellbeing of Future Generations (Wales) Act 2015 — devolved-substantive #3
    'wales-future-generations': wales_future_generations_1.WALES_WBFG_PACK,
    'wales-wbfg': wales_future_generations_1.WALES_WBFG_PACK,
    'wbfg': wales_future_generations_1.WALES_WBFG_PACK,
    'wbfg-wales': wales_future_generations_1.WALES_WBFG_PACK,
    'wellbeing-of-future-generations-wales': wales_future_generations_1.WALES_WBFG_PACK,
    'future-generations-wales': wales_future_generations_1.WALES_WBFG_PACK,
    // Scotland Specific Duties (PSED Scotland — SSI 2012/162) — devolved-substantive #4
    'scotland-psed': scotland_psed_1.SCOTLAND_PSED_PACK,
    'scotland-specific-duties': scotland_psed_1.SCOTLAND_PSED_PACK,
    'psed-scotland': scotland_psed_1.SCOTLAND_PSED_PACK,
    'ssi-2012-162': scotland_psed_1.SCOTLAND_PSED_PACK,
    'scottish-equality-specific-duties': scotland_psed_1.SCOTLAND_PSED_PACK,
    // Health and Social Care Northern Ireland (HSCNI) — devolved-substantive #5
    'ni-hscni': ni_hscni_1.NI_HSCNI_PACK,
    'hscni': ni_hscni_1.NI_HSCNI_PACK,
    'hsc-ni': ni_hscni_1.NI_HSCNI_PACK,
    'health-and-social-care-northern-ireland': ni_hscni_1.NI_HSCNI_PACK,
    'doh-ni': ni_hscni_1.NI_HSCNI_PACK,
    'rqia': ni_hscni_1.NI_HSCNI_PACK,
    // EU Digital Services Act — direct EU mirror of UK Online Safety Act
    'eu-dsa': eu_dsa_1.EU_DSA_PACK,
    'dsa': eu_dsa_1.EU_DSA_PACK,
    'digital-services-act': eu_dsa_1.EU_DSA_PACK,
    'regulation-2022-2065': eu_dsa_1.EU_DSA_PACK,
    'eu-digital-services-act': eu_dsa_1.EU_DSA_PACK,
    // EU Digital Markets Act
    'eu-dma': eu_dma_1.EU_DMA_PACK,
    'dma': eu_dma_1.EU_DMA_PACK,
    'digital-markets-act': eu_dma_1.EU_DMA_PACK,
    'regulation-2022-1925': eu_dma_1.EU_DMA_PACK,
    'eu-digital-markets-act': eu_dma_1.EU_DMA_PACK,
    // NIST CSF 2.0
    'nist-csf': nist_csf_1.NIST_CSF_PACK,
    'nist-csf-2': nist_csf_1.NIST_CSF_PACK,
    'nist-csf-2.0': nist_csf_1.NIST_CSF_PACK,
    'nist-cybersecurity-framework': nist_csf_1.NIST_CSF_PACK,
    'csf': nist_csf_1.NIST_CSF_PACK,
    // NIST SP 800-53 Rev. 5
    'nist-800-53': nist_800_53_1.NIST_800_53_PACK,
    'nist-sp-800-53': nist_800_53_1.NIST_800_53_PACK,
    'sp-800-53': nist_800_53_1.NIST_800_53_PACK,
    '800-53': nist_800_53_1.NIST_800_53_PACK,
    'nist-800-53-rev5': nist_800_53_1.NIST_800_53_PACK,
    // HITRUST CSF
    'hitrust-csf': hitrust_csf_1.HITRUST_CSF_PACK,
    'hitrust': hitrust_csf_1.HITRUST_CSF_PACK,
    'hitrust-common-security-framework': hitrust_csf_1.HITRUST_CSF_PACK,
    'hitrust-e1': hitrust_csf_1.HITRUST_CSF_PACK,
    'hitrust-i1': hitrust_csf_1.HITRUST_CSF_PACK,
    'hitrust-r2': hitrust_csf_1.HITRUST_CSF_PACK,
    // EU Data Act
    'eu-data-act': eu_data_act_1.EU_DATA_ACT_PACK,
    'data-act': eu_data_act_1.EU_DATA_ACT_PACK,
    'eu-data-act-2023': eu_data_act_1.EU_DATA_ACT_PACK,
    'regulation-2023-2854': eu_data_act_1.EU_DATA_ACT_PACK,
    // EU Cyber Resilience Act
    'eu-cra': eu_cra_1.EU_CRA_PACK,
    'cra': eu_cra_1.EU_CRA_PACK,
    'cyber-resilience-act': eu_cra_1.EU_CRA_PACK,
    'eu-cyber-resilience-act': eu_cra_1.EU_CRA_PACK,
    'regulation-2024-2847': eu_cra_1.EU_CRA_PACK,
    // Procurement Reform (Scotland) Act 2014
    'scotland-procurement-reform': scotland_procurement_reform_1.SCOTLAND_PROCUREMENT_PACK,
    'scotland-procurement': scotland_procurement_reform_1.SCOTLAND_PROCUREMENT_PACK,
    'procurement-reform-scotland': scotland_procurement_reform_1.SCOTLAND_PROCUREMENT_PACK,
    'procurement-reform-scotland-act-2014': scotland_procurement_reform_1.SCOTLAND_PROCUREMENT_PACK,
    'asp-2014-12': scotland_procurement_reform_1.SCOTLAND_PROCUREMENT_PACK,
    // Mental Capacity (NI) Act 2016
    'ni-mental-capacity': ni_mental_capacity_1.NI_MCA_PACK,
    'ni-mca': ni_mental_capacity_1.NI_MCA_PACK,
    'ni-mca-2016': ni_mental_capacity_1.NI_MCA_PACK,
    'mental-capacity-ni-2016': ni_mental_capacity_1.NI_MCA_PACK,
    'mental-capacity-northern-ireland-act': ni_mental_capacity_1.NI_MCA_PACK,
    // Hong Kong PDPO
    'hk-pdpo': hk_pdpo_1.HK_PDPO_PACK,
    'hong-kong-pdpo': hk_pdpo_1.HK_PDPO_PACK,
    'pdpo-hk': hk_pdpo_1.HK_PDPO_PACK,
    'cap-486': hk_pdpo_1.HK_PDPO_PACK,
    'personal-data-privacy-ordinance': hk_pdpo_1.HK_PDPO_PACK,
    // Vietnam PDPD
    'vn-pdpd': vn_pdpd_1.VN_PDPD_PACK,
    'vietnam-pdpd': vn_pdpd_1.VN_PDPD_PACK,
    'vietnam-personal-data-protection': vn_pdpd_1.VN_PDPD_PACK,
    'decree-13-2023': vn_pdpd_1.VN_PDPD_PACK,
    'pdpd-vietnam': vn_pdpd_1.VN_PDPD_PACK,
    // Thailand PDPA
    'th-pdpa': th_pdpa_1.TH_PDPA_PACK,
    'thailand-pdpa': th_pdpa_1.TH_PDPA_PACK,
    'pdpa-thailand': th_pdpa_1.TH_PDPA_PACK,
    'thailand-personal-data-protection-act': th_pdpa_1.TH_PDPA_PACK,
    // China DSL + CSL
    'cn-dsl-csl': cn_dsl_csl_1.CN_DSL_CSL_PACK,
    'china-dsl': cn_dsl_csl_1.CN_DSL_CSL_PACK,
    'china-csl': cn_dsl_csl_1.CN_DSL_CSL_PACK,
    'china-dsl-csl': cn_dsl_csl_1.CN_DSL_CSL_PACK,
    'data-security-law-china': cn_dsl_csl_1.CN_DSL_CSL_PACK,
    'cybersecurity-law-china': cn_dsl_csl_1.CN_DSL_CSL_PACK,
    'mlps-china': cn_dsl_csl_1.CN_DSL_CSL_PACK,
    // NIH Certificate of Confidentiality
    'us-nih-coc': us_nih_coc_1.NIH_COC_PACK,
    'nih-coc': us_nih_coc_1.NIH_COC_PACK,
    'nih-certificate-of-confidentiality': us_nih_coc_1.NIH_COC_PACK,
    // NIH Data Management and Sharing
    'us-nih-dms': us_nih_dms_1.NIH_DMS_PACK,
    'nih-dms': us_nih_dms_1.NIH_DMS_PACK,
    'nih-data-management': us_nih_dms_1.NIH_DMS_PACK,
    // NIH Genomic Data Sharing
    'us-nih-gds': us_nih_gds_1.NIH_GDS_PACK,
    'nih-gds': us_nih_gds_1.NIH_GDS_PACK,
    'nih-genomic-data-sharing': us_nih_gds_1.NIH_GDS_PACK,
    // NIH IT Security
    'us-nih-it-security': us_nih_it_security_1.NIH_IT_SECURITY_PACK,
    'nih-it-security': us_nih_it_security_1.NIH_IT_SECURITY_PACK,
    'nih-fisma': us_nih_it_security_1.NIH_IT_SECURITY_PACK,
    // Utah AI Policy Act
    'utah-ai-policy': utah_ai_policy_1.UTAH_AI_POLICY_PACK,
    'ut-ai-policy': utah_ai_policy_1.UTAH_AI_POLICY_PACK,
    'utah-ai': utah_ai_policy_1.UTAH_AI_POLICY_PACK,
    // RTCA DO-178C / EUROCAE ED-12C — Software Considerations in Airborne Systems
    'do-178c': do_178c_1.DO_178C_PACK,
    'do178c': do_178c_1.DO_178C_PACK,
    'rtca-do-178c': do_178c_1.DO_178C_PACK,
    'ed-12c': do_178c_1.DO_178C_PACK,
    'avionics-software': do_178c_1.DO_178C_PACK,
    // FDA 21 CFR Part 820 — Quality System Regulation (QSR / QMSR)
    'fda-21-cfr-820': fda_21_cfr_820_1.FDA_21_CFR_820_PACK,
    'fda-820': fda_21_cfr_820_1.FDA_21_CFR_820_PACK,
    'fda-qsr': fda_21_cfr_820_1.FDA_21_CFR_820_PACK,
    'fda-qmsr': fda_21_cfr_820_1.FDA_21_CFR_820_PACK,
    '21-cfr-820': fda_21_cfr_820_1.FDA_21_CFR_820_PACK,
    // IEC 62304 — Medical Device Software Life Cycle Processes
    'iec-62304': iec_62304_1.IEC_62304_PACK,
    'iec62304': iec_62304_1.IEC_62304_PACK,
    'medical-device-software': iec_62304_1.IEC_62304_PACK,
    // FDA 21 CFR Part 56 (IRB Regulations)
    'us-fda-21cfr56': us_fda_21cfr56_1.US_FDA_21CFR56_PACK,
    'fda-21cfr56': us_fda_21cfr56_1.US_FDA_21CFR56_PACK,
    '21-cfr-56': us_fda_21cfr56_1.US_FDA_21CFR56_PACK,
    'fda-irb': us_fda_21cfr56_1.US_FDA_21CFR56_PACK,
    // ISO 26262 — Automotive Functional Safety
    'iso-26262': iso_26262_1.ISO_26262_PACK,
    'iso26262': iso_26262_1.ISO_26262_PACK,
    'automotive-functional-safety': iso_26262_1.ISO_26262_PACK,
    // IEC 62443 — Industrial Automation and Control Systems Security
    'iec-62443': iec_62443_1.IEC_62443_PACK,
    'iec62443': iec_62443_1.IEC_62443_PACK,
    'industrial-control-systems-security': iec_62443_1.IEC_62443_PACK,
    // NIST SP 800-82 — US Federal Operational Technology Security
    'nist-sp-800-82': nist_sp_800_82_1.NIST_SP_800_82_PACK,
    'nist80082': nist_sp_800_82_1.NIST_SP_800_82_PACK,
    'us-ot-security': nist_sp_800_82_1.NIST_SP_800_82_PACK,
    // AS9100D / AS9110C / AS9120B — Aerospace Quality Management Systems
    'as-9100': as_9100_1.AS_9100_PACK,
    'as9100': as_9100_1.AS_9100_PACK,
    'aerospace-qms': as_9100_1.AS_9100_PACK,
    'as9110': as_9100_1.AS_9100_PACK,
    'as9120': as_9100_1.AS_9100_PACK,
    // FDA Software Pre-Cert + SaMD TPLC + AI/ML Action Plan
    'fda-samd-precert': fda_samd_precert_1.FDA_SAMD_PRECERT_PACK,
    'fdaSamdPrecert': fda_samd_precert_1.FDA_SAMD_PRECERT_PACK,
    // ISO 15189:2022 Medical Laboratory Quality and Competence
    'iso-15189': iso_15189_1.ISO_15189_PACK,
    'iso15189': iso_15189_1.ISO_15189_PACK,
    'medical-laboratory': iso_15189_1.ISO_15189_PACK,
    'clinical-laboratory': iso_15189_1.ISO_15189_PACK,
    // ISO/IEC 80001 Medical IT Network Risk Management
    'iso-iec-80001': iso_iec_80001_1.ISO_IEC_80001_PACK,
    'iso80001': iso_iec_80001_1.ISO_IEC_80001_PACK,
    'medical-it-network': iso_iec_80001_1.ISO_IEC_80001_PACK,
    'hospital-it-risk': iso_iec_80001_1.ISO_IEC_80001_PACK,
};
// ---------------------------------------------------------------------------
// Internal adapter that applies GovernanceRule[] (rule-based, no filesystem)
// ---------------------------------------------------------------------------
class RuleBasedAdapter extends index_1.BaseGovernanceAdapter {
    rules;
    defaultDeny;
    constructor(rules, defaultDeny) {
        super();
        this.rules = rules;
        this.defaultDeny = defaultDeny;
    }
    preAction(context) {
        // Evaluate rules in order; first match wins
        for (const rule of this.rules) {
            if (this.matchesTool(rule.tool, context.toolName)) {
                if (rule.conditions && !this.matchesConditions(rule.conditions, context)) {
                    continue;
                }
                switch (rule.decision) {
                    case 'allow':
                        return (0, index_1.allow)(rule.reason);
                    case 'deny':
                        return this.applyHumanInTheLoop((0, index_1.deny)(rule.reason));
                    case 'require_approval':
                        return (0, index_1.requireApproval)(rule.reason);
                }
            }
        }
        // No rule matched: apply default
        if (this.defaultDeny) {
            // F-NEW-CRIT-39j-3: tag as adapter default-deny so execute() can convert
            // to PackPolicyViolation (DENY) instead of routing through HITL to
            // REQUIRE_APPROVAL. See execute() comment for rationale.
            return this.applyHumanInTheLoop((0, index_1.deny)('No matching rule. Default deny.', { isAdapterDefaultDeny: true }));
        }
        return (0, index_1.allow)('No matching rule. Default allow.');
    }
    getCapabilities() {
        return {
            preAction: true,
            postAction: true,
            auditLogging: true,
            circuitBreaker: false,
            approvalQueue: true,
            tamperDetection: false,
        };
    }
    matchesTool(pattern, toolName) {
        if (typeof pattern === 'string') {
            // Support wildcard '*' as a catch-all
            if (pattern === '*')
                return true;
            return pattern === toolName;
        }
        return pattern.test(toolName);
    }
    matchesConditions(conditions, context) {
        for (const [key, expected] of Object.entries(conditions)) {
            const actual = context.input[key];
            if (actual !== expected)
                return false;
        }
        return true;
    }
}
// ---------------------------------------------------------------------------
// Factory function
// ---------------------------------------------------------------------------
function createGovernedAgent(config) {
    const { name, rules = [], defaultDeny = true, humanInTheLoop = true, onDecision, onError, auditDir, packs: packIds = [], eventBusDir, _packEvaluator: injectedEvaluator, pendingApprovalSubmitter, } = config;
    // 1. Create rule-based adapter with HITL enabled
    const adapter = new RuleBasedAdapter(rules, defaultDeny);
    adapter.initialize({
        adapterName: name,
        platform: config.platform,
        humanInTheLoop,
    });
    // 2. Load compliance packs
    const packRegistry = new index_2.PackRegistry();
    for (const packId of packIds) {
        const normalizedId = packId.toLowerCase().replace(/[\s-_]/g, '');
        // Try direct match first, then normalized
        const pack = exports.BUILT_IN_PACKS[packId] ?? exports.BUILT_IN_PACKS[normalizedId];
        if (pack) {
            // PLACEHOLDER packs must not auto-activate without explicit operator opt-in.
            // A PLACEHOLDER pack bundles multiple jurisdictions whose per-jurisdiction
            // obligations have not yet been confirmed by Vera + counsel. Activating a
            // PLACEHOLDER pack without the explicit opt-in flag throws so the operator
            // is forced to make a conscious decision.
            // F-NEW-VERA-PACK-FINAL-004 (2026-05-03): lpo2024 downgraded to PLACEHOLDER.
            // PLACEHOLDER status is signalled by the pack description containing
            // 'PLACEHOLDER STATUS' (set in pack file when Vera files a FINAL-004-class finding).
            const isPlaceholder = typeof pack.description === 'string' &&
                pack.description.includes('PLACEHOLDER STATUS');
            if (isPlaceholder && !config.allowPlaceholderPacks) {
                throw new Error(`Pack '${pack.id}' has status PLACEHOLDER and cannot be auto-activated without ` +
                    `explicit operator opt-in. Set allowPlaceholderPacks: true in createGovernedAgent() ` +
                    `options after completing Vera + counsel sign-off per the pack file's ` +
                    `OPERATOR_VERIFICATION_REQUIRED notice.`);
            }
            packRegistry.register(pack);
            packRegistry.activate(pack.id);
        }
        else {
            // MissingPackError: fail loud instead of silently ignoring.
            // A customer requesting a non-existent pack gets zero enforcement with
            // no feedback otherwise -- that is a worse outcome than throwing.
            // If backwards-compat requires softer handling, catch MissingPackError
            // at the call site and demote to a warning.
            const knownKeys = Object.keys(exports.BUILT_IN_PACKS).slice(0, 20).join(', ');
            throw new MissingPackError(packId, `Pack '${packId}' is not registered in BUILT_IN_PACKS. ` +
                `Known pack keys (sample): ${knownKeys}... ` +
                `Check src/governed-agent.ts BUILT_IN_PACKS for the full list.`);
        }
    }
    // 3. Set up PackEvaluator for synchronous pack-policy enforcement.
    //    The evaluator runs BEFORE adapter.preAction() in execute().
    //    When packIds is empty, getActive() returns [] and every call produces
    //    ALLOW -- preserving full backward compat for agents without packs.
    let packEvaluator;
    if (injectedEvaluator) {
        // Test injection: use the provided evaluator directly.
        packEvaluator = injectedEvaluator;
    }
    else {
        // Production path: create evaluator from the packRegistry built above.
        const ebDir = eventBusDir ?? auditDir ?? fs.mkdtempSync(path.join(os.tmpdir(), 'ga-eb-'));
        const eventBus = new event_bus_1.EventBus({ eventDir: ebDir, agentName: name });
        packEvaluator = new pack_evaluator_1.PackEvaluator(packRegistry, eventBus);
    }
    // 4. Set up audit trail
    const auditTrail = [];
    // 5. Ensure audit directory if specified
    if (auditDir) {
        try {
            if (!fs.existsSync(auditDir)) {
                fs.mkdirSync(auditDir, { recursive: true });
            }
        }
        catch (err) {
            if (onError) {
                onError(err);
            }
        }
    }
    // 5a. Tamper-evident JSONL writer.
    //
    // AuditIntegrity manages the hash chain: reads the last line of today's file
    // on construction (crash recovery), then appends entries with _seq, _prevHash,
    // and _hash fields. The prefix 'audit' matches the existing file-naming
    // convention (audit-{date}.jsonl) so new chained entries continue in the same
    // per-day files. Legacy flat entries (pre-fix) have no _hash field; the
    // initializeFromExisting guard detects this and resets the chain to seq=0 /
    // prevHash=''. Those legacy entries will report TAMPERED in verify-chain --
    // that is expected and documented; only entries written after this fix carry
    // integrity fields.
    const auditIntegrity = auditDir
        ? new audit_integrity_1.AuditIntegrity({ logDir: auditDir, prefix: 'audit' })
        : null;
    // 6. Track decisions for compliance scoring
    let totalDecisions = 0;
    let allowedDecisions = 0;
    let deniedDecisions = 0;
    function writeAuditEntry(entry) {
        if (!auditDir || !auditIntegrity)
            return;
        try {
            // Cast AuditEntry to Record<string, unknown> for the integrity layer.
            // The chained wrapper adds _seq / _prevHash / _hash on top of the entry
            // data, which the verify-chain CLI expects under the 'data' key.
            auditIntegrity.append(entry);
        }
        catch (err) {
            if (onError) {
                onError(err);
            }
        }
    }
    // 7. Build and return the GovernedAgent
    const agent = {
        async execute(context) {
            try {
                // --- Pack evaluator gate (runs BEFORE adapter.preAction) ---
                // Derive tenantId from context; fall back to agent name for single-tenant use.
                const tenantId = context.orgId ?? context.agent?.orgId ?? name;
                const agentId = context.agent?.name ?? name;
                const packVerdict = packEvaluator.evaluate(tenantId, agentId, context);
                if (packVerdict.verdict === 'DENY') {
                    // Hard block: throw so the caller receives a clear governance signal.
                    // Do NOT call adapter.preAction() -- the pack already decided.
                    throw new PackPolicyViolation(packVerdict.reason, packVerdict.triggeringPackIds, 
                    // F-NEW-CRIT-39i-2: surface classifier IDs to the chain.
                    packVerdict.triggeringClassifierIds ?? []);
                }
                if (packVerdict.verdict === 'PENDING') {
                    // Human review required. Return REQUIRE_APPROVAL with the pending
                    // approval ID surfaced in metadata. Do NOT call adapter.preAction().
                    // The pack-verdict-adapter submits the record to storage asynchronously;
                    // we await it here so the caller can pluck the ID immediately.
                    //
                    // DI path: if a pendingApprovalSubmitter was injected at construction
                    // time (multi-package deployments), call it directly. This eliminates
                    // the async dynamic-import boundary in the hot path.
                    //
                    // Fallback path: dynamic import of pack-verdict-adapter for single-
                    // package / unit-test deployments where no submitter is injected.
                    // The graceful degrade (try/catch) preserves backward compat.
                    let pendingApprovalId;
                    const verdictPayload = {
                        ...packVerdict,
                        tenantId,
                        agentId,
                        actionContext: {
                            toolName: context.toolName,
                            args: context.input,
                        },
                    };
                    try {
                        if (pendingApprovalSubmitter) {
                            // Injected DI: synchronous call, no dynamic import.
                            const record = await pendingApprovalSubmitter(verdictPayload);
                            pendingApprovalId = record.id;
                        }
                        else {
                            // Legacy dynamic-import path: keeps single-package deployments working.
                            const { submitPendingApprovalForPackVerdict } = await Promise.resolve(`${'../packages/governance-server/src/pack-verdict-adapter.js'}`).then(s => __importStar(require(s)));
                            const record = await submitPendingApprovalForPackVerdict(verdictPayload);
                            pendingApprovalId = record.id;
                        }
                    }
                    catch {
                        // Storage unavailable (e.g., in unit tests without a server running).
                        // Still return REQUIRE_APPROVAL -- just without a tracked approval ID.
                    }
                    const pendingDecision = {
                        type: index_1.ActionDecisionType.REQUIRE_APPROVAL,
                        reason: packVerdict.reason,
                        metadata: {
                            source: 'pack-evaluator',
                            pendingApprovalId,
                            triggeringPackIds: packVerdict.triggeringPackIds,
                            triggeringClassifierIds: packVerdict.triggeringClassifierIds,
                        },
                    };
                    totalDecisions++;
                    deniedDecisions++;
                    const pendingEntry = {
                        timestamp: new Date().toISOString(),
                        agentName: name,
                        toolName: context.toolName,
                        decision: pendingDecision,
                        context,
                    };
                    auditTrail.push(pendingEntry);
                    writeAuditEntry(pendingEntry);
                    if (onDecision)
                        onDecision(pendingDecision);
                    return pendingDecision;
                }
                // packVerdict.verdict === 'ALLOW': fall through to adapter.preAction().
                const decision = adapter.preAction(context);
                // F-NEW-CRIT-39j-3: detect adapter default-deny (no rule matched).
                // When isAdapterDefaultDeny=true in metadata (set by RuleBasedAdapter),
                // convert to PackPolicyViolation so the check-action handler returns
                // DENY (not REQUIRE_APPROVAL via HITL). Rationale:
                //   (a) No rule matched = no compliance context for a reviewer.
                //   (b) REQUIRE_APPROVAL creates a dead-letter approval record.
                //   (c) Fail-closed: DENY is the correct answer when nothing allows it.
                // Explicit rule deny (e.g. { tool:'Bash', decision:'deny' }) does NOT
                // set isAdapterDefaultDeny and continues to REQUIRE_APPROVAL as before.
                const isAdapterDefaultDeny = decision.metadata
                    ?.isAdapterDefaultDeny === true;
                if (isAdapterDefaultDeny) {
                    throw new PackPolicyViolation('No compliance rule or pack policy covers this action. ' +
                        'Default deny in effect. Add an explicit allow rule or activate a pack.', [], [], true);
                }
                totalDecisions++;
                if (decision.type === index_1.ActionDecisionType.ALLOW) {
                    allowedDecisions++;
                }
                else {
                    deniedDecisions++;
                }
                const entry = {
                    timestamp: new Date().toISOString(),
                    agentName: name,
                    toolName: context.toolName,
                    decision,
                    context,
                };
                auditTrail.push(entry);
                writeAuditEntry(entry);
                if (onDecision) {
                    onDecision(decision);
                }
                return decision;
            }
            catch (err) {
                // PackPolicyViolation is intentional -- re-throw so callers can
                // distinguish a governance block from an unexpected runtime error.
                if (err instanceof PackPolicyViolation) {
                    throw err;
                }
                const error = err;
                if (onError) {
                    onError(error);
                }
                // On unexpected error, default to deny for safety
                return (0, index_1.deny)(`Governance error: ${error.message}`);
            }
        },
        getAuditTrail() {
            return [...auditTrail];
        },
        getComplianceScore() {
            if (totalDecisions === 0)
                return 100;
            // Compliance score:
            // - Every decision (allow or deny) that followed a rule is compliant
            // - The score reflects how well governance is being enforced
            // - A system that correctly denies bad actions scores high
            // - Factor in pack validation results
            let score = 100;
            // Pack validation contributes to score
            const packResults = packRegistry.validate();
            if (packResults.length > 0) {
                const avgPackScore = packResults.reduce((sum, r) => sum + r.score, 0) / packResults.length;
                // Weight: 50% governance activity, 50% pack compliance
                score = Math.round((score + avgPackScore) / 2);
            }
            return Math.max(0, Math.min(100, score));
        },
        async shutdown() {
            // Flush any remaining audit entries
            if (auditDir && auditTrail.length > 0) {
                const summaryFile = path.join(auditDir, `session-summary-${Date.now()}.json`);
                const summary = {
                    agentName: name,
                    platform: config.platform,
                    totalDecisions,
                    allowedDecisions,
                    deniedDecisions,
                    complianceScore: agent.getComplianceScore(),
                    shutdownTime: new Date().toISOString(),
                };
                try {
                    fs.writeFileSync(summaryFile, JSON.stringify(summary, null, 2));
                }
                catch (err) {
                    if (onError) {
                        onError(err);
                    }
                }
            }
        },
    };
    return agent;
}
//# sourceMappingURL=governed-agent.js.map