/** * AgentGuard(TM) Spend: Advisor governance posture profiles. * * Patent notice: Protected by U.S. patent-pending technology * (App. Nos. 63/983,615; 63/983,621; 63/983,843; 63/984,626; * 64/071,781; 64/071,789). */ import type { CapabilityTier, EnforcementMode } from '../types'; export type GovernancePosture = 'velocity' | 'standard' | 'compliance'; export interface GovernancePostureProfile { posture: GovernancePosture; label: string; defaultMode: EnforcementMode; capabilityStyle: 'permissive' | 'balanced' | 'strict'; downgradeStyle: 'aggressive' | 'moderate' | 'conservative'; auditRetentionDays: number; approvalGates: boolean; canaryPercent?: number; } export const GOVERNANCE_POSTURES: Record = { velocity: { posture: 'velocity', label: 'Velocity', defaultMode: 'shadow', capabilityStyle: 'permissive', downgradeStyle: 'aggressive', auditRetentionDays: 30, approvalGates: false, }, standard: { posture: 'standard', label: 'Standard', defaultMode: 'enforce', capabilityStyle: 'balanced', downgradeStyle: 'moderate', auditRetentionDays: 90, approvalGates: false, }, compliance: { posture: 'compliance', label: 'Compliance', defaultMode: 'canary', capabilityStyle: 'strict', downgradeStyle: 'conservative', auditRetentionDays: 2555, approvalGates: true, canaryPercent: 5, }, }; const VERTICAL_POSTURES: Record = { 'law-firm': 'compliance', healthcare: 'compliance', accounting: 'compliance', fintech: 'compliance', insurance: 'compliance', 'real-estate': 'standard', marketing: 'standard', ecommerce: 'standard', 'local-services': 'standard', dental: 'compliance', software: 'velocity', startup: 'standard', 'ai-lab': 'velocity', 'ai-team': 'velocity', }; export function normalizePosture(value?: string | null): GovernancePosture | null { const normalized = (value ?? '').trim().toLowerCase(); if (normalized === 'velocity' || normalized === 'standard' || normalized === 'compliance') return normalized; return null; } export function postureProfile(posture: GovernancePosture): GovernancePostureProfile { return GOVERNANCE_POSTURES[posture]; } export function suggestPostureForVertical(vertical: string): GovernancePosture { return VERTICAL_POSTURES[vertical] ?? 'standard'; } export function applyPostureCapability( posture: GovernancePosture, text: string, fallback: CapabilityTier, ): CapabilityTier { const lowered = text.toLowerCase(); if (posture === 'velocity') { if (/execute|wire|ach|payout|capture funds/.test(lowered)) return 'payment_execute'; if (/refund|payment|charge|dispute|money|invoice/.test(lowered)) return 'payment_initiate'; return 'read_only'; } if (posture === 'compliance') { if (/refund|payment|charge|dispute|money|invoice|ledger|sox|fintech|bank/.test(lowered)) return 'payment_execute'; if (/write|update|chart|patient|health|phi|pii|legal|contract|tax|student|employment/.test(lowered)) return 'data_write'; return fallback === 'read_only' ? 'data_write' : fallback; } if (/refund|payment|charge|dispute|money|invoice/.test(lowered)) return 'payment_initiate'; if (/write|update|ledger|chart|patient|health|phi|pii|sox|legal|contract|tax|student|employment/.test(lowered)) return 'data_write'; return fallback; } export function postureDescription(posture: GovernancePosture): string { const profile = postureProfile(posture); return `${profile.label}: mode ${profile.defaultMode}, ${profile.capabilityStyle} capabilities, ${profile.downgradeStyle} downgrade chains, ${profile.auditRetentionDays} day audit retention`; }