/ lib / golden-standards / index.ts
index.ts
  1  // ============================================================================
  2  // Golden Standards — Role-specific quality references for AI prompt injection
  3  // ============================================================================
  4  // These files contain industry-grade examples sourced from:
  5  // - Harvard, Stanford, MIT career services
  6  // - Resume Worded, Enhancv, Teal HQ, BeamJobs (real examples)
  7  // - LinkedIn Sales Solutions, Sprout Social (LinkedIn best practices)
  8  // - BrainStation, IGotAnOffer (FAANG-specific examples)
  9  // - Real candidates who landed roles at Google, Stripe, Meta, etc.
 10  //
 11  // Usage: Inject the matching golden standard into prompts as a few-shot
 12  // quality reference. Detect role category first, then load the relevant file.
 13  // ============================================================================
 14  
 15  export type RoleCategory = 'marketing' | 'engineering' | 'ai' | 'sales' | 'starter';
 16  
 17  /**
 18   * Detect the role category from a job title or target role string.
 19   * Returns the closest matching golden standard category.
 20   */
 21  export function detectRoleCategory(role: string): RoleCategory {
 22    const lower = role.toLowerCase();
 23  
 24    // AI/ML detection (check before engineering — AI engineers are a subset)
 25    if (
 26      lower.includes('machine learning') ||
 27      lower.includes('ml ') ||
 28      lower.includes('ai ') ||
 29      lower.includes('artificial intelligence') ||
 30      lower.includes('data scientist') ||
 31      lower.includes('deep learning') ||
 32      lower.includes('nlp') ||
 33      lower.includes('computer vision') ||
 34      lower.includes('llm')
 35    ) {
 36      return 'ai';
 37    }
 38  
 39    // Marketing detection
 40    if (
 41      lower.includes('marketing') ||
 42      lower.includes('brand') ||
 43      lower.includes('content') ||
 44      lower.includes('seo') ||
 45      lower.includes('growth') ||
 46      lower.includes('demand gen') ||
 47      lower.includes('communications') ||
 48      lower.includes('social media') ||
 49      lower.includes('copywriter') ||
 50      lower.includes('creative director')
 51    ) {
 52      return 'marketing';
 53    }
 54  
 55    // Sales detection
 56    if (
 57      lower.includes('sales') ||
 58      lower.includes('account executive') ||
 59      lower.includes('account manager') ||
 60      lower.includes('business development') ||
 61      lower.includes('bdr') ||
 62      lower.includes('sdr') ||
 63      lower.includes('revenue') ||
 64      lower.includes('customer success') ||
 65      lower.includes('partnerships')
 66    ) {
 67      return 'sales';
 68    }
 69  
 70    // Engineering detection
 71    if (
 72      lower.includes('engineer') ||
 73      lower.includes('developer') ||
 74      lower.includes('programmer') ||
 75      lower.includes('architect') ||
 76      lower.includes('devops') ||
 77      lower.includes('sre') ||
 78      lower.includes('frontend') ||
 79      lower.includes('backend') ||
 80      lower.includes('full stack') ||
 81      lower.includes('fullstack') ||
 82      lower.includes('software') ||
 83      lower.includes('cloud')
 84    ) {
 85      return 'engineering';
 86    }
 87  
 88    // Career starter detection (by experience level keywords)
 89    if (
 90      lower.includes('junior') ||
 91      lower.includes('entry') ||
 92      lower.includes('intern') ||
 93      lower.includes('graduate') ||
 94      lower.includes('associate') ||
 95      lower.includes('trainee') ||
 96      lower.includes('apprentice')
 97    ) {
 98      return 'starter';
 99    }
100  
101    // Default to engineering (most common in tech)
102    return 'engineering';
103  }
104  
105  /**
106   * File paths for golden standards by category and type.
107   * These are markdown files that can be read at runtime and injected into prompts.
108   */
109  /**
110   * Load the content of a golden standard file at runtime.
111   * Reads from the filesystem — server-side only.
112   */
113  export async function loadGoldenStandard(
114    type: 'cvs' | 'coverLetters' | 'linkedin',
115    role: string
116  ): Promise<string> {
117    const { readFile } = await import('fs/promises');
118    const { join } = await import('path');
119    const category = detectRoleCategory(role);
120    const relativePath = GOLDEN_STANDARD_PATHS[type][category];
121    try {
122      const fullPath = join(process.cwd(), relativePath);
123      return await readFile(fullPath, 'utf-8');
124    } catch {
125      return ''; // Silently skip if file not found — never block analysis
126    }
127  }
128  
129  export const GOLDEN_STANDARD_PATHS = {
130    cvs: {
131      marketing: 'lib/golden-standards/cvs/marketing.md',
132      engineering: 'lib/golden-standards/cvs/engineering.md',
133      ai: 'lib/golden-standards/cvs/ai.md',
134      sales: 'lib/golden-standards/cvs/sales.md',
135      starter: 'lib/golden-standards/cvs/starter.md',
136    },
137    coverLetters: {
138      marketing: 'lib/golden-standards/cover-letters/marketing.md',
139      engineering: 'lib/golden-standards/cover-letters/engineering.md',
140      ai: 'lib/golden-standards/cover-letters/ai.md',
141      sales: 'lib/golden-standards/cover-letters/sales.md',
142      starter: 'lib/golden-standards/cover-letters/starter.md',
143    },
144    linkedin: {
145      marketing: 'lib/golden-standards/linkedin/marketing.md',
146      engineering: 'lib/golden-standards/linkedin/engineering.md',
147      ai: 'lib/golden-standards/linkedin/ai.md',
148      sales: 'lib/golden-standards/linkedin/sales.md',
149      starter: 'lib/golden-standards/linkedin/starter.md',
150    },
151  } as const;