/** * KnowledgeGateway - Central access point to the presentation knowledge base * * This gateway provides methods to query the knowledge base for: * - Presentation mode selection (keynote vs business) * - Expert methodology recommendations * - Word limits and constraints * - Slide templates * - Quality metrics * - Color palettes * - Anti-patterns to avoid * * The entire presentation engine should query this gateway for EVERY decision. */ import { readFileSync } from 'fs'; import { join, dirname } from 'path'; import { fileURLToPath } from 'url'; import * as yaml from 'yaml'; // ESM-compatible directory resolution function getModuleDir(): string { // @ts-ignore - import.meta.url may not exist in CJS if (typeof import.meta !== 'undefined' && import.meta.url) { // @ts-ignore return dirname(fileURLToPath(import.meta.url)); } // @ts-ignore - __dirname exists in CJS if (typeof __dirname !== 'undefined') { // @ts-ignore return __dirname; } return process.cwd(); } export interface PresentationMode { name: string; use_for: string[]; characteristics: { words_per_slide: string; whitespace: string; visuals: string; structure: string; slides_per_idea?: number; action_titles?: string; }; experts: string[]; } export interface SlideTemplate { name: string; purpose: string; elements?: string[]; components?: string[]; word_limit: number; } export interface QualityMetrics { keynote_mode: Record; business_mode: Record; universal: Record; } export interface ColorPalette { name: string; background: string; primary: string; secondary: string; accent: string; text: string; use_case: string; contrast_ratio: string; } export interface ExpertPrinciple { name: string; description: string; application?: string | string[]; rules?: string[]; } export type PresentationType = | 'ted_keynote' | 'sales_pitch' | 'consulting_deck' | 'investment_banking' | 'investor_pitch' | 'technical_presentation' | 'all_hands'; export class KnowledgeGateway { private kb: any; private loaded = false; constructor() {} /** * Load the knowledge base from YAML file */ async load(): Promise { if (this.loaded) return; const moduleDir = getModuleDir(); const possiblePaths = [ join(moduleDir, '../../assets/presentation-knowledge.yaml'), join(moduleDir, '../assets/presentation-knowledge.yaml'), join(moduleDir, '../../../assets/presentation-knowledge.yaml'), join(moduleDir, 'assets/presentation-knowledge.yaml'), join(process.cwd(), 'assets/presentation-knowledge.yaml'), join(process.cwd(), 'node_modules/claude-presentation-master/assets/presentation-knowledge.yaml') ]; for (const path of possiblePaths) { try { const content = readFileSync(path, 'utf-8'); this.kb = yaml.parse(content); this.loaded = true; console.log(` ✓ Knowledge base loaded from ${path}`); return; } catch { // Try next path } } throw new Error(`Knowledge base not found. Tried: ${possiblePaths.join(', ')}`); } /** * Get presentation mode configuration (keynote or business) */ getMode(mode: 'keynote' | 'business'): PresentationMode { this.ensureLoaded(); return this.kb.presentation_modes[mode]; } /** * Determine which mode is best for a given presentation type */ getModeForType(type: PresentationType): 'keynote' | 'business' { const keynoteTypes: PresentationType[] = ['ted_keynote', 'sales_pitch', 'all_hands']; const businessTypes: PresentationType[] = ['consulting_deck', 'investment_banking', 'investor_pitch', 'technical_presentation']; if (keynoteTypes.includes(type)) return 'keynote'; if (businessTypes.includes(type)) return 'business'; return 'keynote'; // Default } /** * Get word limits for the specified mode */ getWordLimits(mode: 'keynote' | 'business'): { min: number; max: number; ideal: number } { const modeConfig = this.getMode(mode); const range = modeConfig.characteristics.words_per_slide; if (mode === 'keynote') { return { min: 6, max: 15, ideal: 10 }; } else { return { min: 40, max: 80, ideal: 60 }; } } /** * Get bullet point limits */ getBulletLimits(mode: 'keynote' | 'business'): { maxBullets: number; maxWordsPerBullet: number } { if (mode === 'keynote') { return { maxBullets: 3, maxWordsPerBullet: 8 }; } else { return { maxBullets: 5, maxWordsPerBullet: 20 }; } } /** * Get whitespace percentage requirement */ getWhitespaceRequirement(mode: 'keynote' | 'business'): number { if (mode === 'keynote') return 0.40; return 0.25; } /** * Get slide templates for the specified mode */ getSlideTemplates(mode: 'keynote' | 'business'): SlideTemplate[] { this.ensureLoaded(); const key = mode === 'keynote' ? 'keynote_mode' : 'business_mode'; return this.kb.slide_templates[key] || []; } /** * Get a specific slide template by name */ getSlideTemplate(mode: 'keynote' | 'business', templateName: string): SlideTemplate | undefined { const templates = this.getSlideTemplates(mode); return templates.find(t => t.name.toLowerCase().includes(templateName.toLowerCase())); } /** * Get quality metrics for grading */ getQualityMetrics(): QualityMetrics { this.ensureLoaded(); return this.kb.quality_metrics; } /** * Get anti-patterns to avoid */ getAntiPatterns(mode: 'keynote' | 'business'): string[] { this.ensureLoaded(); const key = mode === 'keynote' ? 'keynote_mode' : 'business_mode'; return this.kb.anti_patterns[key] || []; } /** * Get data visualization anti-patterns */ getDataVizAntiPatterns(): string[] { this.ensureLoaded(); return this.kb.anti_patterns.data_visualization || []; } /** * Get accessibility anti-patterns */ getAccessibilityAntiPatterns(): string[] { this.ensureLoaded(); return this.kb.anti_patterns.accessibility || []; } /** * Get color palette by name */ getColorPalette(name: string): ColorPalette | undefined { this.ensureLoaded(); const palettes = this.kb.design_system.color_palettes; return palettes[name]; } /** * Get recommended color palette for presentation type */ getRecommendedPalette(type: PresentationType): ColorPalette { this.ensureLoaded(); const palettes = this.kb.design_system.color_palettes; switch (type) { case 'consulting_deck': return palettes.consulting_classic; case 'investment_banking': case 'investor_pitch': return palettes.executive_professional; case 'ted_keynote': return palettes.dark_executive; case 'sales_pitch': return palettes.modern_business; case 'technical_presentation': return palettes.modern_business; case 'all_hands': return palettes.strategy_growth; default: return palettes.consulting_classic; } } /** * Get typography guidelines for mode */ getTypography(mode: 'keynote' | 'business'): Record { this.ensureLoaded(); const key = mode === 'keynote' ? 'keynote_mode' : 'business_mode'; return this.kb.design_system.typography[key]; } /** * Get story framework by name */ getStoryFramework(name: 'sparkline' | 'scqa' | 'pyramid' | 'scr'): any { this.ensureLoaded(); return this.kb.story_frameworks[name]; } /** * Get expert principles by name */ getExpertPrinciples(expertName: string): any { this.ensureLoaded(); // Check main experts if (this.kb.experts[expertName]) { return this.kb.experts[expertName]; } // Check data viz experts if (this.kb.data_visualization_experts) { for (const key of Object.keys(this.kb.data_visualization_experts)) { if (key.includes(expertName.toLowerCase())) { return this.kb.data_visualization_experts[key]; } } } return null; } /** * Get Duarte's glance test requirements */ getDuarteGlanceTest(): { wordLimit: number; timeSeconds: number } { this.ensureLoaded(); const duarte = this.kb.experts.nancy_duarte; return { wordLimit: duarte.core_principles.glance_test.word_limit || 25, timeSeconds: 3 }; } /** * Get Miller's Law constraints */ getMillersLaw(): { minItems: number; maxItems: number } { this.ensureLoaded(); return { minItems: 5, maxItems: 9 }; } /** * Get cognitive load constraints */ getCognitiveLoadLimits(): { maxItemsPerChunk: number } { this.ensureLoaded(); return { maxItemsPerChunk: 7 }; } /** * Get chart selection guidance */ getChartGuidance(purpose: 'comparison' | 'composition' | 'distribution' | 'relationship'): any { this.ensureLoaded(); return this.kb.chart_selection_guide.by_purpose[purpose]; } /** * Get charts to avoid */ getChartsToAvoid(): string[] { this.ensureLoaded(); const knaflic = this.kb.data_visualization_experts.cole_nussbaumer_knaflic; return knaflic.chart_guidance.avoid_these || []; } /** * Get investment banking pitch book structure */ getIBPitchBookStructure(type: 'ma_sell_side' | 'ma_buy_side' | 'ipo_pitchbook'): any { this.ensureLoaded(); return this.kb.investment_banking?.pitch_book_types[type]; } /** * Check if knowledge base is loaded */ private ensureLoaded(): void { if (!this.loaded) { throw new Error('Knowledge base not loaded. Call load() first.'); } } /** * Get the full knowledge base (for advanced queries) */ getRawKB(): any { this.ensureLoaded(); return this.kb; } } // Singleton instance let gatewayInstance: KnowledgeGateway | null = null; /** * Get or create the KnowledgeGateway instance */ export async function getKnowledgeGateway(): Promise { if (!gatewayInstance) { gatewayInstance = new KnowledgeGateway(); await gatewayInstance.load(); } return gatewayInstance; } /** * Initialize and return the gateway */ export async function initKnowledgeGateway(): Promise { return getKnowledgeGateway(); }