← back to Dw Boardroom Governance

src/types.ts

206 lines

// ═══════════════════════════════════════════════
// DW Boardroom Governance — Core Types
// ═══════════════════════════════════════════════

// Decision classification: A=Autonomous, B=Advisory, C=Controlled
export type DecisionType = 'A' | 'B' | 'C';
export type DecisionStatus = 'pending' | 'approved' | 'rejected' | 'modified' | 'deferred' | 'auto_approved';
export type HumanDecision = 'approve' | 'reject' | 'modify' | 'defer';
export type GovernanceMode = 'supervised' | 'autonomous';
export type RiskLevel = 'low' | 'medium' | 'high' | 'critical';
export type DelegationStatus = 'active' | 'completed' | 'revoked' | 'expired';
export type InitiativeStatus = 'proposed' | 'active' | 'paused' | 'completed' | 'cancelled';
export type MeetingStatus = 'scheduled' | 'in_progress' | 'completed' | 'halted' | 'crashed';

// Meeting phases — ported from boardroom meeting-engine.js
export const MEETING_PHASES = [
  'caucus', 'call_to_order', 'old_business', 'current_business',
  'breakout', 'new_business', 'minutes', 'adjournment'
] as const;
export type MeetingPhase = typeof MEETING_PHASES[number];

// ─── Core Models ────────────────────────────────

export interface Decision {
  id: string;
  topic: string;
  decision_type: DecisionType;
  recommendation: string | null;
  human_decision: HumanDecision | null;
  owner: string;
  autonomy_level: number;
  deadline: string | null;
  status: DecisionStatus;
  source: string | null;
  score: number | null;
  reasoning: string | null;
  notes: string | null;
  created_at: string;
  resolved_at: string | null;
}

export interface DelegationContract {
  id: string;
  decision_id: string | null;
  owner: string;
  delegate: string;
  autonomy_level: number;
  metric: string | null;
  checkpoint_date: string | null;
  status: DelegationStatus;
  routing_keywords: string[] | null;
  hierarchy_path: string | null;
  created_at: string;
  completed_at: string | null;
}

export interface Initiative {
  id: string;
  title: string;
  description: string | null;
  driver_agent: string;
  kpi: string | null;
  risk_level: RiskLevel;
  capital_allocated: number;
  status: InitiativeStatus;
  progress: number;
  created_at: string;
  updated_at: string;
}

export interface Meeting {
  id: string;
  meeting_type: string;
  phase: string;
  started_at: string | null;
  ended_at: string | null;
  status: MeetingStatus;
  attendees: string[];
  summary: string | null;
  action_items: any[];
  created_at: string;
}

export interface MeetingMessage {
  id: number;
  meeting_id: string;
  agent_id: string;
  agent_name: string;
  message: string;
  message_type: string;
  created_at: string;
}

export interface EscalationEntry {
  id: number;
  decision_id: string | null;
  escalation_type: string;
  hours_elapsed: number | null;
  action_taken: string | null;
  escalated_to: string | null;
  created_at: string;
}

export interface GovernanceConfig {
  key: string;
  value: any;
  updated_at: string;
}

// ─── Agenda ─────────────────────────────────────

export interface AgendaItem {
  driver: string;
  topic: string;
  recommendation: string;
  decisionType: DecisionType;
  decisionRequired: boolean;
}

export interface MeetingRequest {
  meetingType: string;
  agendaItems?: AgendaItem[];
}

// ─── WebSocket Events ───────────────────────────

export type WSEventType =
  | 'connected'
  | 'meeting_phase'
  | 'meeting_started'
  | 'meeting_halted'
  | 'meeting_completed'
  | 'meeting_message'
  | 'new_decision'
  | 'decision_resolved'
  | 'escalation'
  | 'delegation_created'
  | 'config_changed';

export interface WSEvent {
  type: WSEventType;
  payload: any;
  timestamp: string;
}

// ─── Task Scoring (ported from task-reaper.js) ──

export const SCORE_THRESHOLDS = {
  VETO_CEILING: 2,      // 0-2 = auto-cancel
  RESOLVE_CEILING: 6,   // 3-6 = auto-approve if autonomy >= 4
  // 7-10 = always requires human decision
} as const;

// ─── Agent Hierarchy (ported from delegation-engine.js) ──

export const EXEC_DELEGATES: Record<string, string[]> = {
  ceo: ['frank', 'connie', 'chet', 'george', 'ken'],
  cfo: ['grant', 'nash', 'hugh', 'annie', 'shane'],
  coo: ['max', 'hawk', 'clay', 'rex', 'steve', 'abby'],
  cto: ['vince', 'link', 'nate', 'ross'],
  vpops: [
    'atlas', 'bob', 'sage', 'faye', 'drew', 'chase', 'blake', 'dean', 'clark', 'clyde',
    'ralph', 'sasha', 'knox', 'cleo', 'elise', 'artie',
    'kira', 'maya', 'pj', 'ines', 'beau', 'tate',
    'brock', 'york', 'graham', 'jade', 'will', 'scout'
  ],
};

// Keyword → agent routing (ported from delegation-engine.js TASK_KEYWORDS)
export const TASK_KEYWORDS: Record<string, string> = {
  legal: 'frank', compliance: 'frank', trademark: 'frank', settlement: 'frank',
  competitor: 'connie', competitive: 'connie', market: 'connie',
  slack: 'chet', communications: 'chet', message: 'chet', notify: 'chet',
  email: 'george', gmail: 'george', inbox: 'george',
  trading: 'ken', trade: 'ken', investment: 'ken',
  finance: 'grant', accounting: 'grant', ledger: 'grant', revenue: 'grant',
  expense: 'nash', cost: 'nash', spending: 'nash',
  purchasing: 'hugh', procurement: 'hugh', vendor: 'hugh', purchase: 'hugh',
  pricing: 'annie', arbitrage: 'annie', price: 'annie', margin: 'annie',
  shopify: 'shane', store: 'shane', product: 'shane', order: 'shane',
  monitor: 'hawk', alert: 'hawk', cpu: 'hawk', memory: 'hawk',
  schedule: 'clay', cron: 'clay', recurring: 'clay',
  timeout: 'rex', process: 'rex', zombie: 'rex', frozen: 'rex',
  server: 'steve', infrastructure: 'steve', nginx: 'steve',
  uptime: 'vince', website: 'vince', ssl: 'vince',
  central: 'link', coordination: 'link', sync: 'link',
  agenda: 'abby',
  directory: 'ross', agent: 'ross',
  notes: 'nate', minutes: 'nate',
  blog: 'bob', content: 'bob', seo: 'bob', article: 'bob',
  trend: 'sage', forecast: 'sage', research: 'sage',
  room: 'faye', staging: 'faye', scene: 'faye', furniture: 'faye',
  sample: 'drew', digital: 'drew',
  image: 'chase', ghost: 'chase',
  collection: 'dean', collections: 'dean',
  sku: 'clyde', audit: 'clyde',
  pipeline: 'blake', scheduler: 'blake',
  update: 'clark', updates: 'clark',
  'ralph lauren': 'ralph', schumacher: 'sasha', kravet: 'knox',
  'cole & son': 'cleo', 'cole son': 'cleo', elitis: 'elise', arte: 'artie',
  koroseal: 'kira', 'maya romanoff': 'maya', 'phillip jeffries': 'pj',
  innovations: 'ines', bespoke: 'beau', thibaut: 'tate',
  brewster: 'brock', york: 'york', 'graham & brown': 'graham', 'graham brown': 'graham',
  'glass bead': 'jade', catalog: 'atlas', scrape: 'scout', crawl: 'scout',
};