"use strict";
/**
 * ISO/IEC 23894:2023 Compliance Pack
 *
 * Information technology -- Artificial intelligence -- Guidance on
 * risk management. Published February 2023 as the risk-management
 * companion to ISO/IEC 42001 (AIMS).
 *
 * Standards referenced:
 *   - ISO/IEC 23894:2023 (AI risk management guidance)
 *   - ISO 31000:2018 (generic risk management -- foundation)
 *   - ISO/IEC 42001:2023 (AIMS -- complementary system)
 *   - ISO/IEC Guide 73 (risk management vocabulary)
 *
 * Structure:
 *   - Clause 4: Principles (aligned with ISO 31000)
 *   - Clause 5: Framework
 *   - Clause 6: Process (communication, scope, assessment, treatment,
 *     monitoring, review, recording)
 *   - Annex A: AI-specific risk areas (training data, bias,
 *     robustness, human oversight, transparency, safety, security,
 *     privacy, accountability, societal, environmental)
 *
 * Certification: guidance only (not certifiable on its own). Cited
 * as evidence of mature AI risk practice.
 *
 * @connexum/ai-governance
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.ISO_23894_PACK = exports.ISO_23894_CATEGORY_CLASSIFIERS = void 0;
/**
 * ISO 23894:2023 (AI Risk Management) category classifiers.
 * ISO 23894 governs AI risk management process flows (risk identification,
 * analysis, treatment, monitoring). Classification targets training data,
 * risk data, PII, and credentials per §6.7 (recording) and §6.3 (identification).
 */
exports.ISO_23894_CATEGORY_CLASSIFIERS = {
    AI_TRAINING_DATA: {
        references: ['ISO 23894 §6.3 -- AI risk identification; training data provenance and quality'],
        classifier: (input) => {
            if (/\b(?:AI\s+training\s+(?:data|set|sample)|training\s+dataset|model\s+(?:weights?|training))\b/i.test(input))
                return true;
            if (/\b(?:training\s+corpus|fine.?tuning\s+data|RLHF\s+data|preference\s+data)\b/i.test(input))
                return true;
            return false;
        },
    },
    AI_RISK_DATA: {
        references: ['ISO 23894 §6.7 -- recording; AI risk register entries'],
        classifier: (input) => {
            if (/\b(?:AI\s+risk\s+(?:register|assessment|data|record|finding)|risk\s+treatment\s+(?:plan|decision))\b/i.test(input))
                return true;
            if (/\b(?:risk\s+acceptance|residual\s+risk|risk\s+owner|risk\s+rating)\b/i.test(input))
                return true;
            return false;
        },
    },
    PII: {
        references: ['ISO 23894 -- personal data used in AI risk management documentation'],
        classifier: (input) => {
            if (/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/.test(input))
                return true;
            if (/\b\d{3}-\d{2}-\d{4}\b/.test(input))
                return true;
            return false;
        },
    },
    CREDENTIALS: {
        references: ['ISO 23894 -- information security for AI risk management systems'],
        classifier: (input) => {
            if (/\b(?:api[_-]?key|apikey)\s*[=:]\s*["']?[A-Za-z0-9_\-\/+]{16,}["']?/i.test(input))
                return true;
            if (/\bpassword\s*[=:]\s*["']?[A-Za-z0-9!@#$%^&*_\-]{8,}["']?/i.test(input))
                return true;
            if (/\bAKIA[A-Z0-9]{16}\b/.test(input))
                return true;
            if (/-----BEGIN\s+(?:RSA\s+)?PRIVATE\s+KEY-----/.test(input))
                return true;
            return false;
        },
    },
    // -------------------------------------------------------------------------
    // Five new Annex A categories added by F-NEW-VERA-PACK-C4-04 (Kai, 2026-05-03)
    // Severity: LOG/WARN -- ISO 23894 is a guidance standard, not a regulatory
    // mandate with hard enforcement obligations. LOG surfaces provenance records;
    // WARN flags areas where governance gaps carry reputational or legal exposure.
    // -------------------------------------------------------------------------
    /**
     * AI_BIAS_RISK_RECORD -- ISO 23894 Annex A bias / fairness risk area.
     * Covers records of bias assessments, fairness evaluations, and disparate
     * treatment findings. Severity: WARN (bias findings require documented
     * treatment plans under ISO 23894 §6.5; regulators cite untreated bias
     * as evidence of inadequate AI risk management).
     */
    AI_BIAS_RISK_RECORD: {
        references: ['ISO 23894 Annex A -- bias risk area; fairness and non-discrimination'],
        classifier: (input) => {
            if (/\b(?:bias\s+(?:assessment|evaluation|finding|risk|metric|score)|fairness\s+(?:metric|score|evaluation|assessment))\b/i.test(input))
                return true;
            if (/\b(?:disparate\s+(?:treatment|impact)|demographic\s+parity|equalized\s+odds|calibration\s+error)\b/i.test(input))
                return true;
            if (/\b(?:protected\s+attribute|sensitive\s+attribute|group\s+fairness|individual\s+fairness)\b/i.test(input))
                return true;
            return false;
        },
    },
    /**
     * AI_ROBUSTNESS_RECORD -- ISO 23894 Annex A robustness risk area.
     * Covers robustness testing records, adversarial evaluation findings, and
     * brittleness or out-of-distribution failure documentation.
     * Severity: WARN (robustness failures are a direct AI risk identified in
     * ISO 23894 §6.4.4; brittleness in production constitutes residual risk
     * that must be documented and treated).
     */
    AI_ROBUSTNESS_RECORD: {
        references: ['ISO 23894 Annex A -- robustness risk area; §6.4.4 robustness monitoring'],
        classifier: (input) => {
            if (/\b(?:adversarial\s+(?:robustness|testing|attack|example|input)|robustness\s+(?:testing|evaluation|score|metric|failure))\b/i.test(input))
                return true;
            if (/\b(?:brittleness|brittle\s+model|distribution\s+shift|out.of.distribution|OOD\s+(?:performance|failure|input))\b/i.test(input))
                return true;
            if (/\b(?:model\s+degradation|performance\s+drift|concept\s+drift|covariate\s+shift)\b/i.test(input))
                return true;
            return false;
        },
    },
    /**
     * AI_HUMAN_OVERSIGHT_RECORD -- ISO 23894 Annex A human oversight risk area;
     * §6.4.3 explicitly requires human oversight level to be determined per
     * decision type. Covers HITL documentation, human supervision logs, and
     * oversight level declarations.
     * Severity: WARN (ISO 23894 §6.4.3 is normative guidance; absence of
     * documented human oversight is a primary audit finding. WARN is proportionate
     * for a guidance standard while surfacing the record for review).
     */
    AI_HUMAN_OVERSIGHT_RECORD: {
        references: ['ISO 23894 §6.4.3 -- human oversight level; Annex A human oversight risk area'],
        classifier: (input) => {
            if (/\b(?:human.in.the.loop|human\s+in\s+the\s+loop|HITL|human\s+oversight|human\s+supervision)\b/i.test(input))
                return true;
            if (/\b(?:oversight\s+level|human\s+review\s+(?:required|mandatory|gate)|human\s+approval\s+required)\b/i.test(input))
                return true;
            if (/\b(?:manual\s+review\s+gate|human\s+escalation|human\s+validator|human\s+auditor)\b/i.test(input))
                return true;
            return false;
        },
    },
    /**
     * AI_SOCIETAL_IMPACT_RECORD -- ISO 23894 Annex A societal impact risk area.
     * Covers records of community harm assessments, democratic discourse risks,
     * and public welfare evaluations for deployed AI systems.
     * Severity: LOG (societal impact records are informational in most governance
     * contexts; ISO 23894 requires the field to be tracked but does not mandate
     * treatment in all cases -- LOG surfaces the record without over-blocking).
     */
    AI_SOCIETAL_IMPACT_RECORD: {
        references: ['ISO 23894 Annex A -- societal impact risk area'],
        classifier: (input) => {
            if (/\b(?:societal\s+impact|social\s+impact\s+assessment|community\s+harm|harm\s+to\s+(?:the\s+)?community)\b/i.test(input))
                return true;
            if (/\b(?:democratic\s+(?:discourse|process|integrity)|public\s+welfare|civic\s+(?:harm|risk)|misinformation\s+risk)\b/i.test(input))
                return true;
            if (/\b(?:societal\s+risk|broad\s+societal\s+(?:harm|effect|impact)|large.scale\s+social\s+harm)\b/i.test(input))
                return true;
            return false;
        },
    },
    /**
     * AI_ENVIRONMENTAL_IMPACT_RECORD -- ISO 23894 Annex A environmental impact
     * risk area. Covers energy consumption records, carbon footprint measurements,
     * and compute emissions documentation for AI training and inference workloads.
     * Severity: LOG (environmental impact is an emerging governance requirement;
     * ISO 23894 lists it as a risk area but most jurisdictions have not yet
     * mandated hard enforcement -- LOG is proportionate for current posture).
     */
    AI_ENVIRONMENTAL_IMPACT_RECORD: {
        references: ['ISO 23894 Annex A -- environmental impact risk area'],
        classifier: (input) => {
            if (/\b(?:carbon\s+footprint|carbon\s+emissions?|CO2\s+emissions?|tCO2e|compute\s+emissions?)\b/i.test(input))
                return true;
            if (/\b(?:energy\s+consumption|power\s+usage\s+effectiveness|PUE|GPU\s+hours?|training\s+energy)\b/i.test(input))
                return true;
            if (/\b(?:sustainability\s+(?:metric|threshold|target|score)|green\s+(?:AI|computing|infrastructure)|environmental\s+(?:impact|cost|footprint))\b/i.test(input))
                return true;
            return false;
        },
    },
};
exports.ISO_23894_PACK = {
    categoryClassifiers: exports.ISO_23894_CATEGORY_CLASSIFIERS,
    id: 'iso-23894',
    name: 'ISO/IEC 23894 (AI Risk Management)',
    version: '1.0.0',
    contentHash: '51f8487e39d29f88ec729f412b6328b338338e729649bd3d94e43c6cd8d0c78b',
    description: 'ISO/IEC 23894:2023 AI Risk Management Guidance. Applies ISO 31000 principles to AI-specific risks (training data, bias, robustness, human oversight, transparency, safety, security, privacy, accountability, societal, environmental). Companion to ISO/IEC 42001 AIMS.',
    authority: 'ISO/IEC JTC 1/SC 42',
    industries: ['technology', 'healthcare', 'finance', 'government', 'manufacturing', 'consulting', 'ai-foundation-model-provider', 'critical-infrastructure'],
    requiredModules: [
        {
            name: 'governance-runtime',
            required: true,
            reason: 'AI risk management framework + scope + context',
            reference: 'ISO 23894 Clause 5 Framework',
        },
        {
            name: 'audit-integrity',
            required: true,
            reason: 'Risk recording + reporting per ISO 23894 §6.7',
            reference: 'ISO 23894 §6.7 Recording and Reporting',
        },
        {
            name: 'data-classifier',
            required: true,
            reason: 'AI_TRAINING_DATA + AI_RISK_DATA + AI_BIAS_RISK_RECORD + AI_ROBUSTNESS_RECORD + AI_HUMAN_OVERSIGHT_RECORD + AI_SOCIETAL_IMPACT_RECORD + AI_ENVIRONMENTAL_IMPACT_RECORD classification',
            reference: 'ISO 23894 Annex A (training data risk)',
        },
        {
            name: 'session-persistence',
            required: true,
            reason: 'Risk assessment state; risk treatment decision continuity',
            reference: 'ISO 23894 §6.4-6.5',
        },
        {
            name: 'supply-chain',
            required: true,
            reason: 'Third-party AI / data risks; supply-chain scope',
            reference: 'ISO 23894 §6.3 Scope, Context, Criteria',
        },
        {
            name: 'approval-queue',
            required: true,
            reason: 'Risk treatment decisions (accept / avoid / mitigate / transfer); human oversight level per ISO 23894 §6.4.3',
            reference: 'ISO 23894 §6.4.3 + §6.5 Risk Treatment',
        },
        {
            name: 'attestation-manager',
            required: true,
            reason: 'AI risk management process attestation + risk register + annual review',
            reference: 'ISO 23894 §5, §6.4, §6.6',
        },
        {
            name: 'anomaly-detector',
            required: true,
            reason: 'Robustness monitoring + distribution shift detection',
            reference: 'ISO 23894 §6.4.4 + §6.6 Monitoring and Review',
        },
        {
            name: 'bias-monitor',
            required: true,
            reason: 'Training data bias + fairness risk',
            reference: 'ISO 23894 Annex A bias risk area',
        },
        {
            name: 'transparency-injector',
            required: true,
            reason: 'Transparency / explainability evidence per decision',
            reference: 'ISO 23894 §6.4.5 + Annex A',
        },
        {
            name: 'event-bus',
            required: true,
            reason: 'Risk communication + stakeholder consultation events',
            reference: 'ISO 23894 §6.2 Communication and Consultation',
        },
    ],
    moduleConfig: {
        'governance-runtime': {
            aiRiskFrameworkRequired: true,
            iso31000AlignmentRequired: true,
        },
        'data-classifier': {
            enabledCategories: [
                'AI_TRAINING_DATA',
                'AI_RISK_DATA',
                'AI_BIAS_RISK_RECORD',
                'AI_ROBUSTNESS_RECORD',
                'AI_HUMAN_OVERSIGHT_RECORD',
                'AI_SOCIETAL_IMPACT_RECORD',
                'AI_ENVIRONMENTAL_IMPACT_RECORD',
                'PII',
                'CREDENTIALS',
            ],
            trainingDataProvenanceRequired: true,
        },
        'session-persistence': {
            riskAssessmentStateRequired: true,
            riskTreatmentDecisionContinuityRequired: true,
        },
        'supply-chain': {
            thirdPartyAiRiskRequired: true,
        },
        'approval-queue': {
            humanOversightLevelTracked: true,
            riskTreatmentDecisionRequired: true,
        },
        'attestation-manager': {
            aiRiskManagementProcessAttestationRequired: true,
            aiRiskRegisterRequired: true,
            annualRiskReviewRequired: true,
            societalImpactFieldRequired: true,
            environmentalImpactFieldRequired: true,
        },
        'anomaly-detector': {
            robustnessMonitoringActive: true,
            distributionShiftDetectionActive: true,
        },
        'bias-monitor': {
            trainingDataBiasAssessmentRequired: true,
        },
        'transparency-injector': {
            explainabilityEvidenceRequired: true,
        },
        'event-bus': {
            riskCommunicationEventsActive: true,
        },
    },
    providerPolicy: {
        blockedProviders: [],
        requiredCapabilities: ['ISO-23894-ALIGNED'],
        blockReasons: {},
    },
    dataPolicy: {
        scanCategories: [
            'AI_TRAINING_DATA',
            'AI_RISK_DATA',
            'AI_BIAS_RISK_RECORD',
            'AI_ROBUSTNESS_RECORD',
            'AI_HUMAN_OVERSIGHT_RECORD',
            'AI_SOCIETAL_IMPACT_RECORD',
            'AI_ENVIRONMENTAL_IMPACT_RECORD',
            'PII',
            'CREDENTIALS',
        ],
        categoryActions: {
            AI_TRAINING_DATA: 'LOG',
            AI_RISK_DATA: 'LOG',
            // WARN: bias and robustness findings carry governance exposure --
            // surface immediately for risk treatment review per ISO 23894 §6.5.
            AI_BIAS_RISK_RECORD: 'WARN',
            AI_ROBUSTNESS_RECORD: 'WARN',
            // WARN: human oversight gaps are a primary ISO 23894 §6.4.3 audit finding.
            AI_HUMAN_OVERSIGHT_RECORD: 'WARN',
            // LOG: societal + environmental are tracked fields; guidance standard posture.
            AI_SOCIETAL_IMPACT_RECORD: 'LOG',
            AI_ENVIRONMENTAL_IMPACT_RECORD: 'LOG',
            PII: 'WARN',
            CREDENTIALS: 'BLOCK',
        },
        encryptionRequired: true,
        encryptionStandard: 'AES-256-GCM',
        minimumClassification: 'INTERNAL',
    },
    retentionPolicy: {
        sovereignty: ['GLOBAL'],
        auditLogRetentionDays: 1095, // 3 years aligned with risk review cycle
        sessionRetentionDays: 365,
        incidentRetentionDays: 1095,
        reference: 'ISO 23894 §6.7 Recording -- retained per organisational risk review cycle (typically 3 years)',
    },
    incidentPolicy: {
        notificationDeadlineHours: 72,
        reference: 'ISO 23894 is guidance (no statutory deadline). Pax1 defaults to 72-hour internal escalation + risk register update within 7 business days.',
        requiredRecipients: ['risk-management', 'ai-owner', 'senior-leadership'],
        formalNotificationRequired: false,
    },
    validators: [
        {
            id: 'iso23894-framework',
            description: 'AI risk management framework documented (Clause 5)',
            reference: 'ISO 23894 §5',
            check: 'iso23894_framework_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'iso23894-process',
            description: 'Risk management process active (§6.1-6.7)',
            reference: 'ISO 23894 §6',
            check: 'iso23894_process_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'iso23894-risk-register',
            description: 'AI risk register maintained per agent',
            reference: 'ISO 23894 §6.4 Risk Assessment',
            check: 'iso23894_risk_register_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'iso23894-training-data',
            description: 'Training data quality + provenance + fairness evaluated',
            reference: 'ISO 23894 Annex A',
            check: 'iso23894_training_data_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'iso23894-robustness',
            description: 'Robustness monitoring + distribution shift detection active',
            reference: 'ISO 23894 §6.4.4',
            check: 'iso23894_robustness_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'iso23894-human-oversight',
            description: 'Human oversight level tracked per decision type',
            reference: 'ISO 23894 §6.4.3',
            check: 'iso23894_human_oversight_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'iso23894-transparency',
            description: 'Transparency + explainability evidence captured',
            reference: 'ISO 23894 §6.4.5',
            check: 'iso23894_transparency_active',
            failSeverity: 'MEDIUM',
        },
        {
            id: 'iso23894-societal-impact',
            description: 'Societal impact field tracked per AI system',
            reference: 'ISO 23894 Annex A',
            check: 'iso23894_societal_impact_active',
            failSeverity: 'MEDIUM',
        },
        {
            id: 'iso23894-risk-treatment',
            description: 'Risk treatment decision documented (accept / avoid / mitigate / transfer)',
            reference: 'ISO 23894 §6.5',
            check: 'iso23894_risk_treatment_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'iso23894-monitoring-review',
            description: 'Periodic risk review at minimum annually',
            reference: 'ISO 23894 §6.6',
            check: 'iso23894_monitoring_review_active',
            failSeverity: 'MEDIUM',
        },
        {
            id: 'iso23894-communication',
            description: 'Risk communication with stakeholders active',
            reference: 'ISO 23894 §6.2',
            check: 'iso23894_communication_active',
            failSeverity: 'MEDIUM',
        },
    ],
};
//# sourceMappingURL=iso-23894.js.map