/**
 * ABA Model Rules Compliance Pack (Generative AI framework)
 *
 * Primary source: ABA Formal Opinion 512 (29 July 2024). Applies the
 * existing ABA Model Rules of Professional Conduct to generative AI
 * use by lawyers. State bar adoption and supplemental guidance varies;
 * Pax1 treats ABA as the anchor pack, with the Regulatory Tracker
 * agent layering state-specific overlays (CA, FL, NY, DC, PA, MI,
 * TX, WA, VA, NC, NJ and others).
 *
 * Core rules implicated:
 *   - Rule 1.1 Competence (cite-check, verification)
 *   - Rule 1.3 Diligence
 *   - Rule 1.4 Communication (client informed consent for AI use)
 *   - Rule 1.5 Fees (no billing for time not spent)
 *   - Rule 1.6 Confidentiality (no outbound to retaining / training
 *     providers without consent)
 *   - Rules 1.7-1.9 Conflicts (per-matter isolation)
 *   - Rule 3.3 Candor to the Tribunal (hallucinated citations)
 *   - Rules 5.1-5.3 Supervision (supervising-lawyer gate)
 *   - Rule 5.5 Unauthorized Practice of Law (jurisdiction scope)
 *   - Rules 7.1-7.3 Marketing (truthfulness of AI-generated marketing)
 *
 * No federal statute; enforcement via state bars. Sanctions for Rule
 * 3.3 violations also reachable via FRCP 11 and 28 USC 1927.
 *
 * @connexum/ai-governance
 */
/**
 * ABA (American Bar Association) Model Rules category classifiers.
 * Governs AI use in legal practice: privilege, work-product, and
 * client confidentiality under Model Rules 1.1, 1.6, 5.3.
 */
export const ABA_CATEGORY_CLASSIFIERS = {
    PRIVILEGED: {
        references: ['ABA Model Rule 1.6 -- confidentiality of information; attorney-client privilege'],
        classifier: (input) => {
            if (/\b(?:attorney.?client\s+privilege|privileged\s+communication|legal\s+advice|legal\s+counsel)\b/i.test(input))
                return true;
            if (/\b(?:confidential\s+(?:legal|attorney|client)|privileged\s+(?:and\s+)?confidential)\b/i.test(input))
                return true;
            return false;
        },
    },
    ATTORNEY_WORK_PRODUCT: {
        references: ['ABA Model Rule 1.1 -- competence; work product doctrine; Fed. R. Civ. P. 26(b)(3)'],
        classifier: (input) => {
            if (/\b(?:attorney\s+work\s+product|work\s+product\s+doctrine|trial\s+preparation|litigation\s+strategy)\b/i.test(input))
                return true;
            if (/\b(?:mental\s+impressions|legal\s+strategy|case\s+assessment|case\s+theory)\b/i.test(input))
                return true;
            return false;
        },
    },
    PII: {
        references: ['ABA Model Rule 1.6(c) -- reasonable efforts to prevent disclosure; client PII'],
        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: ['ABA Model Rule 1.6(c) -- safeguarding client information; credential protection'],
        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;
        },
    },
};
export const ABA_PACK = {
    categoryClassifiers: ABA_CATEGORY_CLASSIFIERS,
    /** P3.5: Privileged and attorney work product are subject-keyed (privilege belongs to a specific client). */
    subjectKeyedCategories: ['PRIVILEGED', 'ATTORNEY_WORK_PRODUCT'],
    id: 'aba',
    /**
     * GAP-S1-01: site/packs.html public codes for this pack.
     * LG-01 = MRPC 1.6 Confidentiality
     * LG-02 = MRPC 1.10 Ethical Walls / Imputed Conflicts
     * Both are subsets of the ABA Model Rules covered by this pack.
     */
    aliases: ['LG-01', 'LG-02'],
    name: 'ABA Model Rules',
    version: '1.0.0',
    description: 'ABA Model Rules of Professional Conduct framework for generative AI use by lawyers, anchored by ABA Formal Opinion 512 (July 2024). Covers competence, confidentiality, supervision, communication, candor, conflicts, UPL, fees, and marketing.',
    authority: 'American Bar Association (Formal Opinion 512) + state bar associations',
    industries: ['legal', 'law-firm', 'legal-ops', 'legal-tech', 'in-house-legal'],
    requiredModules: [
        {
            name: 'governance-runtime',
            required: true,
            reason: 'Supervising-lawyer gate; UPL / jurisdiction scope enforcement',
            reference: 'Rules 5.1-5.3, 5.5',
        },
        {
            name: 'audit-integrity',
            required: true,
            reason: 'Tamper-evident record of privileged-content decisions, client consent, supervising-lawyer reviews',
            reference: 'Rule 1.6 (confidentiality evidence); Opinion 512',
        },
        {
            name: 'data-classifier',
            required: true,
            reason: 'Detect PRIVILEGED and ATTORNEY_WORK_PRODUCT; flag uncited case references',
            reference: 'Rule 1.6; Rule 3.3',
        },
        {
            name: 'session-persistence',
            required: true,
            reason: 'Per-matter isolation; client informed-consent tracking; conflict check per new matter',
            reference: 'Rules 1.7-1.9; Rule 1.4',
        },
        {
            name: 'supply-chain',
            required: true,
            reason: 'Verify every legal-AI vendor has zero-retention, zero-training-on-inputs, client-data-segregation terms',
            reference: 'Rule 1.6; Opinion 512',
        },
        {
            name: 'approval-queue',
            required: true,
            reason: 'Human-lawyer review gate for court filings; fee reasonableness gate for AI time entries; AI-marketing truthfulness gate',
            reference: 'Rules 3.3, 1.5, 7.1-7.3',
        },
        {
            name: 'attestation-manager',
            required: true,
            reason: 'Supervising lawyer on file per agent; client consent on file per matter',
            reference: 'Rules 5.1-5.3; Rule 1.4',
        },
        {
            name: 'transparency-injector',
            required: true,
            reason: 'Client-facing disclosures about AI use in the representation',
            reference: 'Rule 1.4; Opinion 512',
        },
        {
            name: 'agent-auth',
            required: true,
            reason: 'Agent identity for privilege boundary + jurisdiction scope',
            reference: 'Rules 5.1-5.3, 5.5',
        },
        {
            name: 'event-bus',
            required: true,
            reason: 'Stream privilege-decision events, hallucinated-citation alerts, confidentiality incidents',
            reference: 'Rule 1.6; Rule 3.3',
        },
    ],
    moduleConfig: {
        'data-classifier': {
            enabledCategories: [
                'PRIVILEGED',
                'ATTORNEY_WORK_PRODUCT',
                'PII',
                'CREDENTIALS',
            ],
            privilegedAction: 'BLOCK_UNLESS_CONSENTED',
            workProductAction: 'BLOCK_UNLESS_CONSENTED',
        },
        'session-persistence': {
            perMatterIsolationRequired: true,
            conflictCheckRequired: true,
            clientInformedConsentRequired: true,
        },
        'supply-chain': {
            vendorZeroRetentionRequired: true,
            vendorZeroTrainingOnInputsRequired: true,
            vendorClientDataSegregationRequired: true,
        },
        'approval-queue': {
            courtFilingRequiresLawyerReview: true,
            feeReasonablenessReviewRequired: true,
            marketingTruthfulnessReviewRequired: true,
        },
        'attestation-manager': {
            supervisingLawyerRequiredPerAgent: true,
        },
        'governance-runtime': {
            upljurisdictionScopeRequired: true,
        },
    },
    providerPolicy: {
        blockedProviders: [],
        requiredCapabilities: ['ZERO-RETENTION', 'ZERO-TRAINING-ON-INPUTS'],
        blockReasons: {},
    },
    dataPolicy: {
        scanCategories: ['PRIVILEGED', 'ATTORNEY_WORK_PRODUCT', 'PII', 'CREDENTIALS'],
        categoryActions: {
            PRIVILEGED: 'BLOCK',
            ATTORNEY_WORK_PRODUCT: 'BLOCK',
            PII: 'WARN',
            CREDENTIALS: 'BLOCK',
        },
        encryptionRequired: true,
        encryptionStandard: 'AES-256',
        minimumClassification: 'CONFIDENTIAL',
    },
    retentionPolicy: {
        sovereignty: ['US'],
        // 7 years aligned with typical state bar file-retention
        auditLogRetentionDays: 2555,
        sessionRetentionDays: 365,
        incidentRetentionDays: 2555,
        reference: 'Typical state bar file-retention 7 years; varies by state',
    },
    incidentPolicy: {
        // 7 days for client notification of confidentiality breach (default; firm policy may be faster)
        notificationDeadlineHours: 168,
        reference: 'Opinion 512 requires prompt client notification of confidentiality breaches; Pax1 default 7 days external + 24h internal escalation.',
        requiredRecipients: ['affected-clients', 'managing-partner', 'ethics-counsel'],
        formalNotificationRequired: true,
    },
    validators: [
        {
            id: 'aba-competence-citecheck',
            description: 'Cite-check evidence required before court filings submitted',
            reference: 'Rule 1.1; Rule 3.3; Opinion 512',
            check: 'aba_citecheck_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'aba-confidentiality-gate',
            description: 'Privileged / work product data blocked from retaining or training providers without consent',
            reference: 'Rule 1.6; Opinion 512',
            check: 'aba_confidentiality_gate_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'aba-supervision',
            description: 'Supervising lawyer on file for every agent',
            reference: 'Rules 5.1-5.3',
            check: 'aba_supervision_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'aba-filing-review',
            description: 'Human lawyer approval required on every AI-drafted court filing before submission',
            reference: 'Rule 3.3; Opinion 512',
            check: 'aba_filing_review_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'aba-client-consent',
            description: 'Client informed consent recorded for AI use in the matter',
            reference: 'Rule 1.4; Opinion 512',
            check: 'aba_client_consent_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'aba-conflicts',
            description: 'Per-matter isolation and conflict check before agent touches a new matter',
            reference: 'Rules 1.7-1.9',
            check: 'aba_conflicts_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'aba-upl',
            description: 'Jurisdiction scope enforced per agent; UPL prevented',
            reference: 'Rule 5.5',
            check: 'aba_upl_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'aba-fee-reasonableness',
            description: 'Fee entries for AI processing time flagged for reasonableness review',
            reference: 'Rule 1.5',
            check: 'aba_fee_review_active',
            failSeverity: 'MEDIUM',
        },
        {
            id: 'aba-marketing-truth',
            description: 'AI-generated marketing materials pass human-lawyer truthfulness review',
            reference: 'Rules 7.1-7.3',
            check: 'aba_marketing_review_active',
            failSeverity: 'MEDIUM',
        },
        {
            id: 'aba-vendor-terms',
            description: 'Every legal-AI vendor verified zero-retention + zero-training-on-inputs + client-data-segregation',
            reference: 'Rule 1.6; Opinion 512',
            check: 'aba_vendor_terms_active',
            failSeverity: 'HIGH',
        },
    ],
};
//# sourceMappingURL=aba.js.map