Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
Remove hard coded keywords for matching
Khuram Niaze79cb3bd7331
diff --git a/__tests__/ai.actions.spec.ts b/__tests__/ai.actions.spec.tsindex 30c2551..972ea9d 100644--- a/__tests__/ai.actions.spec.ts+++ b/__tests__/ai.actions.spec.ts@@ -3,25 +3,13 @@* Tests for the new mathematical scoring and multi-agent collaboration system*/-// Mock AI utility functions-jest.mock("@/utils/ai.utils", () => ({- convertResumeToText: jest.fn(),- convertJobToText: jest.fn(),-}));-import {countQuantifiedAchievements,- extractKeywords,- countActionVerbs,- calculateKeywordOverlap,analyzeFormatting,- extractRequiredSkills,calculateResumeScore,calculateJobMatchScore,validateScore,} from "@/lib/ai";-import { Resume, SectionType } from "@/models/profile.model";-import { convertResumeToText, convertJobToText } from "@/utils/ai.utils";describe("AI Library - Analysis Tools", () => {describe("countQuantifiedAchievements", () => {@@ -54,78 +42,9 @@ describe("AI Library - Analysis Tools", () => {});});- describe("extractKeywords", () => {- it("should extract keywords from text", () => {- const text = "React, TypeScript, Node.js, AWS, Docker";- const result = extractKeywords(text);- expect(result.count).toBeGreaterThan(0);- expect(result.keywords).toContain("react");- });-- it("should normalize keywords to lowercase", () => {- const text = "REACT TypeScript Node.JS";- const result = extractKeywords(text);- result.keywords.forEach((keyword) => {- expect(keyword).toBe(keyword.toLowerCase());- });- });-- it("should return empty array for empty text", () => {- const result = extractKeywords("");- expect(result.keywords).toEqual([]);- expect(result.count).toBe(0);- });- });-- describe("countActionVerbs", () => {- it("should count action verbs in text", () => {- const text =- "Led development. Managed team. Implemented features. Optimized performance.";- const result = countActionVerbs(text);- expect(result.count).toBeGreaterThan(0);- expect(result.verbs.length).toBeGreaterThan(0);- });-- it("should return 0 for text with no action verbs", () => {- const text = "This is some random text without action verbs.";- const result = countActionVerbs(text);- expect(result.count).toBe(0);- expect(result.verbs).toEqual([]);- });- });-- describe("calculateKeywordOverlap", () => {- it("should calculate overlap between resume and job", () => {- const resumeText = "React, TypeScript, Node.js developer";- const jobText = "Looking for React, TypeScript, Angular expert";- const result = calculateKeywordOverlap(resumeText, jobText);- expect(result.overlapPercentage).toBeGreaterThan(0);- expect(result.overlapPercentage).toBeLessThanOrEqual(100);- expect(result.matchedKeywords.length).toBeGreaterThan(0);- });-- it("should return high overlap for similar texts", () => {- const resumeText = "React TypeScript Node.js AWS Docker";- const jobText = "React TypeScript AWS experience required";- const result = calculateKeywordOverlap(resumeText, jobText);- expect(result.overlapPercentage).toBeGreaterThan(50);- expect(result.matchedKeywords).toContain("react");- });-- it("should return low overlap for different texts", () => {- const resumeText = "React TypeScript Node.js";- const jobText = "Java Spring Hibernate";- const result = calculateKeywordOverlap(resumeText, jobText);- expect(result.overlapPercentage).toBeLessThan(40);- expect(result.missingKeywords.length).toBeGreaterThan(0);- });-- it("should return 0 for empty texts", () => {- const result = calculateKeywordOverlap("", "");- expect(result.overlapPercentage).toBe(0);- expect(result.matchedKeywords).toEqual([]);- });- });+ // Note: extractKeywords, countActionVerbs, calculateKeywordOverlap tests removed+ // These functions now use semantic AI extraction (extractSemanticKeywords, analyzeActionVerbs, etc.)+ // which require AI providers and cannot be easily unit tested without mockingdescribe("analyzeFormatting", () => {it("should detect bullet points", () => {@@ -149,30 +68,7 @@ describe("AI Library - Analysis Tools", () => {});});- describe("extractRequiredSkills", () => {- it("should extract skills from job description with sections", () => {- const jobText = `Requirements:-- React-- TypeScript-- Node.js--Preferred Skills:-- Docker-- AWS`;- const result = extractRequiredSkills(jobText);- // Since it looks for specific section markers, results may vary- expect(result).toHaveProperty("requiredSkills");- expect(result).toHaveProperty("preferredSkills");- expect(result).toHaveProperty("totalSkills");- });-- it("should return empty arrays for empty job text", () => {- const result = extractRequiredSkills("");- expect(result.requiredSkills).toEqual([]);- expect(result.preferredSkills).toEqual([]);- expect(result.totalSkills).toBe(0);- });- });+ // Note: extractRequiredSkills tests removed - function now uses semantic AI extraction});describe("AI Library - Mathematical Scoring", () => {diff --git a/__tests__/ai.library.spec.ts b/__tests__/ai.library.spec.tsindex aff8684..c69513d 100644--- a/__tests__/ai.library.spec.ts+++ b/__tests__/ai.library.spec.ts@@ -12,11 +12,7 @@import {countQuantifiedAchievements,- extractKeywords,- countActionVerbs,- calculateKeywordOverlap,analyzeFormatting,- extractRequiredSkills,calculateResumeScore,calculateJobMatchScore,validateScore,@@ -53,78 +49,9 @@ describe("AI Library - Analysis Tools", () => {});});- describe("extractKeywords", () => {- it("should extract keywords from text", () => {- const text = "React, TypeScript, Node.js, AWS, Docker";- const result = extractKeywords(text);- expect(result.count).toBeGreaterThan(0);- expect(result.keywords).toContain("react");- });-- it("should normalize keywords to lowercase", () => {- const text = "REACT TypeScript Node.JS";- const result = extractKeywords(text);- result.keywords.forEach((keyword) => {- expect(keyword).toBe(keyword.toLowerCase());- });- });-- it("should return empty array for empty text", () => {- const result = extractKeywords("");- expect(result.keywords).toEqual([]);- expect(result.count).toBe(0);- });- });-- describe("countActionVerbs", () => {- it("should count action verbs in text", () => {- const text =- "Led development. Managed team. Implemented features. Optimized performance.";- const result = countActionVerbs(text);- expect(result.count).toBeGreaterThan(0);- expect(result.verbs.length).toBeGreaterThan(0);- });-- it("should return 0 for text with no action verbs", () => {- const text = "This is some random text without action verbs.";- const result = countActionVerbs(text);- expect(result.count).toBe(0);- expect(result.verbs).toEqual([]);- });- });-- describe("calculateKeywordOverlap", () => {- it("should calculate overlap between resume and job", () => {- const resumeText = "React, TypeScript, Node.js developer";- const jobText = "Looking for React, TypeScript, Angular expert";- const result = calculateKeywordOverlap(resumeText, jobText);- expect(result.overlapPercentage).toBeGreaterThan(0);- expect(result.overlapPercentage).toBeLessThanOrEqual(100);- expect(result.matchedKeywords.length).toBeGreaterThan(0);- });-- it("should return high overlap for similar texts", () => {- const resumeText = "React TypeScript Node.js AWS Docker";- const jobText = "React TypeScript AWS experience required";- const result = calculateKeywordOverlap(resumeText, jobText);- expect(result.overlapPercentage).toBeGreaterThan(50);- expect(result.matchedKeywords).toContain("react");- });-- it("should return low overlap for different texts", () => {- const resumeText = "React TypeScript Node.js";- const jobText = "Java Spring Hibernate";- const result = calculateKeywordOverlap(resumeText, jobText);- expect(result.overlapPercentage).toBeLessThan(40);- expect(result.missingKeywords.length).toBeGreaterThan(0);- });-- it("should return 0 for empty texts", () => {- const result = calculateKeywordOverlap("", "");- expect(result.overlapPercentage).toBe(0);- expect(result.matchedKeywords).toEqual([]);- });- });+ // Note: extractKeywords, countActionVerbs, calculateKeywordOverlap tests removed+ // These functions now use semantic AI extraction (extractSemanticKeywords, analyzeActionVerbs, etc.)+ // which require AI providers and cannot be easily unit tested without mockingdescribe("analyzeFormatting", () => {it("should detect bullet points", () => {@@ -148,30 +75,7 @@ describe("AI Library - Analysis Tools", () => {});});- describe("extractRequiredSkills", () => {- it("should extract skills from job description with sections", () => {- const jobText = `Requirements:-- React-- TypeScript-- Node.js--Preferred Skills:-- Docker-- AWS`;- const result = extractRequiredSkills(jobText);- // Since it looks for specific section markers, results may vary- expect(result).toHaveProperty("requiredSkills");- expect(result).toHaveProperty("preferredSkills");- expect(result).toHaveProperty("totalSkills");- });-- it("should return empty arrays for empty job text", () => {- const result = extractRequiredSkills("");- expect(result.requiredSkills).toEqual([]);- expect(result.preferredSkills).toEqual([]);- expect(result.totalSkills).toBe(0);- });- });+ // Note: extractRequiredSkills tests removed - function now uses semantic AI extraction});describe("AI Library - Mathematical Scoring", () => {diff --git a/__tests__/performance-comparison.spec.ts b/__tests__/performance-comparison.spec.tsindex d9daf26..23c8036 100644--- a/__tests__/performance-comparison.spec.ts+++ b/__tests__/performance-comparison.spec.ts@@ -1,13 +1,11 @@/**- * Performance Comparison Tests: V1 (5 agents) vs V2 (2 agents)- * Phase 2: Measure latency, cost, and quality improvements+ * Multi-Agent System Performance Tests+ * Measures latency, score consistency, and quality*/import {- collaborativeResumeReview,- collaborativeJobMatch,- consolidatedMultiAgentResumeReview,- consolidatedMultiAgentJobMatch,+ multiAgentResumeReview,+ multiAgentJobMatch,type ProviderType,} from "@/lib/ai";@@ -16,7 +14,7 @@ John DoeSenior Software EngineerPROFESSIONAL SUMMARY-Experienced software engineer with 8+ years building scalable web applications.+Experienced software engineer with 8+ years building scalable web applications.Led teams of 5-10 engineers to deliver mission-critical systems.EXPERIENCE@@ -69,10 +67,9 @@ RESPONSIBILITIES:`;interface PerformanceMetrics {- latency: number; // milliseconds+ latency: number;score: number;timestamp: Date;- version: "v1" | "v2";type: "resume" | "job-match";warnings?: string[];}@@ -81,25 +78,17 @@ interface PerformanceMetrics {* Run a single test and collect metrics*/async function runTest(- version: "v1" | "v2",type: "resume" | "job-match"): Promise<PerformanceMetrics> {const startTime = Date.now();try {if (type === "resume") {- const result =- version === "v1"- ? await collaborativeResumeReview(- SAMPLE_RESUME,- "openai" as ProviderType,- "gpt-4o"- )- : await consolidatedMultiAgentResumeReview(- SAMPLE_RESUME,- "openai" as ProviderType,- "gpt-4o"- );+ const result = await multiAgentResumeReview(+ SAMPLE_RESUME,+ "openai" as ProviderType,+ "gpt-4o"+ );const latency = Date.now() - startTime;@@ -107,25 +96,16 @@ async function runTest(latency,score: result.analysis.score,timestamp: new Date(),- version,type,warnings: result.warnings,};} else {- const result =- version === "v1"- ? await collaborativeJobMatch(- SAMPLE_RESUME,- SAMPLE_JOB,- "openai" as ProviderType,- "gpt-4o"- )- : await consolidatedMultiAgentJobMatch(- SAMPLE_RESUME,- SAMPLE_JOB,- "openai" as ProviderType,- "gpt-4o"- );+ const result = await multiAgentJobMatch(+ SAMPLE_RESUME,+ SAMPLE_JOB,+ "openai" as ProviderType,+ "gpt-4o"+ );const latency = Date.now() - startTime;@@ -133,19 +113,17 @@ async function runTest(latency,score: result.analysis.matching_score,timestamp: new Date(),- version,type,warnings: result.warnings,};}} catch (error) {const latency = Date.now() - startTime;- console.error(`Test failed for ${version} ${type}:`, error);+ console.error(`Test failed for ${type}:`, error);return {latency,score: -1,timestamp: new Date(),- version,type,warnings: [error instanceof Error ? error.message : String(error)],};@@ -156,7 +134,6 @@ async function runTest(* Run multiple iterations and calculate statistics*/async function runBenchmark(- version: "v1" | "v2",type: "resume" | "job-match",iterations: number = 3): Promise<{@@ -168,15 +145,13 @@ async function runBenchmark(successRate: number;metrics: PerformanceMetrics[];}> {- console.log(- `\n🏃 Running ${iterations} iterations for ${version} ${type}...`- );+ console.log(`\nRunning ${iterations} iterations for ${type}...`);const metrics: PerformanceMetrics[] = [];for (let i = 0; i < iterations; i++) {console.log(` Iteration ${i + 1}/${iterations}...`);- const result = await runTest(version, type);+ const result = await runTest(type);metrics.push(result);// Wait 2 seconds between iterations to avoid rate limiting@@ -207,151 +182,86 @@ async function runBenchmark(}/**- * Compare V1 vs V2 performance+ * Run performance benchmarks*/-async function compareVersions() {+async function runPerformanceTests() {console.log("=".repeat(80));- console.log("PERFORMANCE COMPARISON: V1 (5 agents) vs V2 (2 agents)");+ console.log("MULTI-AGENT SYSTEM PERFORMANCE TEST");console.log("=".repeat(80));- // Resume Review Comparison- console.log("\n📄 RESUME REVIEW TEST");- const v1Resume = await runBenchmark("v1", "resume", 3);- const v2Resume = await runBenchmark("v2", "resume", 3);+ // Resume Review Test+ console.log("\nRESUME REVIEW TEST");+ const resumeResults = await runBenchmark("resume", 3);- console.log("\n📊 RESUME REVIEW RESULTS:");- console.log(`V1 (5 agents):`);- console.log(` Avg Latency: ${(v1Resume.avgLatency / 1000).toFixed(2)}s`);+ console.log("\nRESUME REVIEW RESULTS:");+ console.log(` Avg Latency: ${(resumeResults.avgLatency / 1000).toFixed(2)}s`);console.log(- ` Range: ${(v1Resume.minLatency / 1000).toFixed(2)}s - ${(- v1Resume.maxLatency / 1000+ ` Range: ${(resumeResults.minLatency / 1000).toFixed(2)}s - ${(+ resumeResults.maxLatency / 1000).toFixed(2)}s`);console.log(- ` Avg Score: ${v1Resume.avgScore.toFixed(+ ` Avg Score: ${resumeResults.avgScore.toFixed(1- )} ± ${v1Resume.scoreVariance.toFixed(1)}`+ )} +/- ${resumeResults.scoreVariance.toFixed(1)}`);- console.log(` Success Rate: ${v1Resume.successRate.toFixed(0)}%`);-- console.log(`\nV2 (2 agents):`);- console.log(` Avg Latency: ${(v2Resume.avgLatency / 1000).toFixed(2)}s`);- console.log(- ` Range: ${(v2Resume.minLatency / 1000).toFixed(2)}s - ${(- v2Resume.maxLatency / 1000- ).toFixed(2)}s`- );- console.log(- ` Avg Score: ${v2Resume.avgScore.toFixed(- 1- )} ± ${v2Resume.scoreVariance.toFixed(1)}`- );- console.log(` Success Rate: ${v2Resume.successRate.toFixed(0)}%`);-- const resumeLatencyImprovement =- ((v1Resume.avgLatency - v2Resume.avgLatency) / v1Resume.avgLatency) * 100;- console.log(- `\n✅ Latency Improvement: ${resumeLatencyImprovement.toFixed(1)}%`- );- console.log(`✅ Cost Reduction: ~60% (5 calls → 2 calls)`);-- // Job Match Comparison- console.log("\n\n💼 JOB MATCH TEST");- const v1Job = await runBenchmark("v1", "job-match", 3);- const v2Job = await runBenchmark("v2", "job-match", 3);+ console.log(` Success Rate: ${resumeResults.successRate.toFixed(0)}%`);- console.log("\n📊 JOB MATCH RESULTS:");- console.log(`V1 (5 agents):`);- console.log(` Avg Latency: ${(v1Job.avgLatency / 1000).toFixed(2)}s`);- console.log(- ` Range: ${(v1Job.minLatency / 1000).toFixed(2)}s - ${(- v1Job.maxLatency / 1000- ).toFixed(2)}s`- );- console.log(- ` Avg Score: ${v1Job.avgScore.toFixed(1)} ± ${v1Job.scoreVariance.toFixed(- 1- )}`- );- console.log(` Success Rate: ${v1Job.successRate.toFixed(0)}%`);+ // Job Match Test+ console.log("\n\nJOB MATCH TEST");+ const jobResults = await runBenchmark("job-match", 3);- console.log(`\nV2 (2 agents):`);- console.log(` Avg Latency: ${(v2Job.avgLatency / 1000).toFixed(2)}s`);+ console.log("\nJOB MATCH RESULTS:");+ console.log(` Avg Latency: ${(jobResults.avgLatency / 1000).toFixed(2)}s`);console.log(- ` Range: ${(v2Job.minLatency / 1000).toFixed(2)}s - ${(- v2Job.maxLatency / 1000+ ` Range: ${(jobResults.minLatency / 1000).toFixed(2)}s - ${(+ jobResults.maxLatency / 1000).toFixed(2)}s`);console.log(- ` Avg Score: ${v2Job.avgScore.toFixed(1)} ± ${v2Job.scoreVariance.toFixed(+ ` Avg Score: ${jobResults.avgScore.toFixed(1- )}`+ )} +/- ${jobResults.scoreVariance.toFixed(1)}`);- console.log(` Success Rate: ${v2Job.successRate.toFixed(0)}%`);-- const jobLatencyImprovement =- ((v1Job.avgLatency - v2Job.avgLatency) / v1Job.avgLatency) * 100;- console.log(`\n✅ Latency Improvement: ${jobLatencyImprovement.toFixed(1)}%`);- console.log(`✅ Cost Reduction: ~60% (5 calls → 2 calls)`);+ console.log(` Success Rate: ${jobResults.successRate.toFixed(0)}%`);// Summaryconsole.log("\n" + "=".repeat(80));console.log("SUMMARY");console.log("=".repeat(80));console.log(- `Average Latency Improvement: ${(- (resumeLatencyImprovement + jobLatencyImprovement) /- 2- ).toFixed(1)}%`+ `Average Latency: ${(+ (resumeResults.avgLatency + jobResults.avgLatency) /+ 2000+ ).toFixed(2)}s`);- console.log(`Cost Reduction: ~60% (5 LLM calls → 2 LLM calls)`);console.log(- `Score Consistency: Both versions show similar scores (±${Math.max(- v1Resume.scoreVariance,- v2Resume.scoreVariance,- v1Job.scoreVariance,- v2Job.scoreVariance- ).toFixed(1)} points)`+ `Score Consistency: +/-${Math.max(+ resumeResults.scoreVariance,+ jobResults.scoreVariance+ ).toFixed(1)} points`);-- // Quality Check- const scoreDiffResume = Math.abs(v1Resume.avgScore - v2Resume.avgScore);- const scoreDiffJob = Math.abs(v1Job.avgScore - v2Job.avgScore);- console.log(`\n📊 Score Difference (V1 vs V2):`);- console.log(` Resume: ${scoreDiffResume.toFixed(1)} points`);- console.log(` Job Match: ${scoreDiffJob.toFixed(1)} points`);-- if (scoreDiffResume <= 5 && scoreDiffJob <= 5) {- console.log(- `\n✅ QUALITY CHECK PASSED: Score differences within acceptable range (≤5 points)`- );- } else {- console.log(- `\n⚠️ QUALITY CHECK WARNING: Score differences may indicate quality degradation`- );- }-- console.log("\n" + "=".repeat(80));+ console.log("=".repeat(80));}// Wrap in describe block for Jest-describe("Performance Comparison: V1 vs V2", () => {- it("should compare V1 and V2 performance", async () => {- await compareVersions();+describe("Multi-Agent System Performance", () => {+ it("should complete resume review and job match successfully", async () => {+ await runPerformanceTests();}, 300000); // 5 minute timeout for comprehensive testing});-// Run the comparison+// Run the benchmarkif (require.main === module) {- compareVersions()+ runPerformanceTests().then(() => {- console.log("\n✅ Comparison complete!");+ console.log("\nBenchmark complete!");process.exit(0);}).catch((error) => {- console.error("\n❌ Comparison failed:", error);+ console.error("\nBenchmark failed:", error);process.exit(1);});}-export { runTest, runBenchmark, compareVersions };+export { runTest, runBenchmark, runPerformanceTests };diff --git a/src/app/api/ai/resume/match-collaborative/route.ts b/src/app/api/ai/resume/match-collaborative/route.tsindex a9f0f61..52d0819 100644--- a/src/app/api/ai/resume/match-collaborative/route.ts+++ b/src/app/api/ai/resume/match-collaborative/route.ts@@ -15,7 +15,7 @@ import { getJobDetails } from "@/actions/job.actions";import { AiModel } from "@/models/ai.model";// Extend timeout for multi-agent collaboration (2 minutes)-// V2 is faster: ~18s typical, allowing 2min for safety+// Typical: ~18s, allowing 2min for safetyexport const maxDuration = 120;export const POST = async (req: NextRequest) => {@@ -74,7 +74,7 @@ export const POST = async (req: NextRequest) => {const progressStream = new ProgressStream(controller);try {- // Run V2 collaborative analysis with progress updates+ // Run collaborative analysis with progress updatesconst { analysis } = await adaptiveJobMatch(resumeText,jobText,diff --git a/src/app/api/ai/resume/match/route.ts b/src/app/api/ai/resume/match/route.tsindex f3340cb..a9e2da3 100644--- a/src/app/api/ai/resume/match/route.ts+++ b/src/app/api/ai/resume/match/route.ts@@ -7,10 +7,11 @@ import { getModel } from "@/lib/ai/providers";import { checkRateLimit } from "@/lib/ai/rate-limiter";import {JobMatchSchema,- ENHANCED_JOB_MATCH_SYSTEM_PROMPT,- buildEnhancedJobMatchPrompt,- calculateKeywordOverlap,- extractKeywords,+ JOB_MATCH_SYSTEM_PROMPT,+ buildJobMatchPrompt,+ performSemanticSkillMatch,+ calculateSemanticSimilarity,+ AIUnavailableError,} from "@/lib/ai";import { convertResumeToText, convertJobToText } from "@/utils/ai.utils";import { getResumeById } from "@/actions/profile.actions";@@ -64,24 +65,37 @@ export const POST = async (req: NextRequest) => {const resumeText = await convertResumeToText(resume);const jobText = await convertJobToText(job);- // Extract keyword analysis for enhanced prompting- const keywordOverlap = calculateKeywordOverlap(resumeText, jobText);- const resumeKeywords = extractKeywords(resumeText);- const jobKeywords = extractKeywords(jobText);+ // Use semantic analysis for skill matching+ const [skillMatch, similarity] = await Promise.all([+ performSemanticSkillMatch(+ resumeText,+ jobText,+ selectedModel.provider,+ selectedModel.model || "llama3.2"+ ),+ calculateSemanticSimilarity(+ resumeText,+ jobText,+ selectedModel.provider,+ selectedModel.model || "llama3.2"+ ),+ ]);++ const matchedSkills = skillMatch.exact_matches.map((m) => m.skill);+ const missingSkills = skillMatch.missing_skills.map((s) => s.skill);+ const totalSkills = matchedSkills.length + missingSkills.length;- const basePrompt = buildEnhancedJobMatchPrompt(resumeText, jobText);- const enhancedPrompt = `${basePrompt}+ const basePrompt = buildJobMatchPrompt(resumeText, jobText);+ const fullPrompt = `${basePrompt}TOOL ANALYSIS RESULTS (use these in your evaluation):-- Keyword overlap: ${keywordOverlap.overlapPercentage}% (${- keywordOverlap.matchedKeywords.length- } of ${keywordOverlap.totalJobKeywords} job keywords found)-- Matched keywords: ${keywordOverlap.matchedKeywords.join(", ") || "none"}-- Missing keywords: ${keywordOverlap.missingKeywords.join(", ") || "none"}-- Resume has ${resumeKeywords.count} technical terms-- Job requires ${jobKeywords.count} technical terms+- Semantic similarity: ${similarity.similarity_score}% match+- Skills matched: ${matchedSkills.length} of ${totalSkills} required skills+- Matched skills: ${matchedSkills.slice(0, 10).join(", ") || "none"}+- Missing skills: ${missingSkills.slice(0, 10).join(", ") || "none"}+- Match explanation: ${similarity.match_explanation}-Use these exact counts in your Step 3 (CALCULATE POINTS) for the Keyword Overlap score.`;+Use these results in your scoring decisions.`;const model = getModel(selectedModel.provider,@@ -91,14 +105,22 @@ Use these exact counts in your Step 3 (CALCULATE POINTS) for the Keyword Overlapconst result = streamObject({model,schema: JobMatchSchema,- system: ENHANCED_JOB_MATCH_SYSTEM_PROMPT,- prompt: enhancedPrompt,+ system: JOB_MATCH_SYSTEM_PROMPT,+ prompt: fullPrompt,temperature: 0.3,});return result.toTextStreamResponse();} catch (error) {console.error("Job match error:", error);++ if (error instanceof AIUnavailableError) {+ return NextResponse.json(+ { error: error.message },+ { status: 503 }+ );+ }+const message =error instanceof Error ? error.message : "AI request failed";diff --git a/src/app/api/ai/resume/review-collaborative/route.ts b/src/app/api/ai/resume/review-collaborative/route.tsindex 81b50f7..e8ba754 100644--- a/src/app/api/ai/resume/review-collaborative/route.ts+++ b/src/app/api/ai/resume/review-collaborative/route.ts@@ -14,7 +14,7 @@ import { Resume } from "@/models/profile.model";import { AiModel } from "@/models/ai.model";// Extend timeout for multi-agent collaboration (2 minutes)-// V2 is faster: ~18s typical, allowing 2min for safety+// Typical: ~18s, allowing 2min for safetyexport const maxDuration = 120;export const POST = async (req: NextRequest) => {@@ -62,7 +62,7 @@ export const POST = async (req: NextRequest) => {const progressStream = new ProgressStream(controller);try {- // Run V2 collaborative analysis with progress updates+ // Run collaborative analysis with progress updatesconst { analysis } = await adaptiveResumeReview(resumeText,selectedModel.provider,diff --git a/src/app/api/ai/resume/review/route.ts b/src/app/api/ai/resume/review/route.tsindex fd10179..601b7fb 100644--- a/src/app/api/ai/resume/review/route.ts+++ b/src/app/api/ai/resume/review/route.ts@@ -7,12 +7,15 @@ import { getModel } from "@/lib/ai/providers";import { checkRateLimit } from "@/lib/ai/rate-limiter";import {ResumeReviewSchema,- ENHANCED_RESUME_REVIEW_SYSTEM_PROMPT,- buildEnhancedResumeReviewPrompt,+ RESUME_REVIEW_SYSTEM_PROMPT,+ buildResumeReviewPrompt,countQuantifiedAchievements,- extractKeywords,- countActionVerbs,analyzeFormatting,+ extractSemanticKeywords,+ analyzeActionVerbs,+ getKeywordCountFromSemantic,+ getVerbCountFromSemantic,+ AIUnavailableError,} from "@/lib/ai";import { convertResumeToText } from "@/utils/ai.utils";import { Resume } from "@/models/profile.model";@@ -58,25 +61,43 @@ export const POST = async (req: NextRequest) => {try {const resumeText = await convertResumeToText(resume);- // Extract tool data for enhanced prompting+ // Extract tool data for enhanced prompting using semantic AI functionsconst quantified = countQuantifiedAchievements(resumeText);- const keywords = extractKeywords(resumeText);- const verbs = countActionVerbs(resumeText);const formatting = analyzeFormatting(resumeText);- const basePrompt = buildEnhancedResumeReviewPrompt(resumeText);- const enhancedPrompt = `${basePrompt}+ // Use semantic extraction for keywords and verbs+ const [semanticKeywords, semanticVerbs] = await Promise.all([+ extractSemanticKeywords(+ resumeText,+ selectedModel.provider,+ selectedModel.model || "llama3.2"+ ),+ analyzeActionVerbs(+ resumeText,+ selectedModel.provider,+ selectedModel.model || "llama3.2"+ ),+ ]);++ const keywordCount = getKeywordCountFromSemantic(semanticKeywords);+ const verbCount = getVerbCountFromSemantic(semanticVerbs);+ const allKeywords = [+ ...semanticKeywords.technical_skills,+ ...semanticKeywords.tools_platforms,+ ];+ const allVerbs = semanticVerbs.strong_verbs.map((v) => v.verb);++ const basePrompt = buildResumeReviewPrompt(resumeText);+ const fullPrompt = `${basePrompt}TOOL ANALYSIS RESULTS (use these in your evaluation):- Quantified achievements found: ${quantified.count} (Examples: ${quantified.examples.join(", ") || "none"})-- Technical keywords found: ${keywords.count} (${- keywords.keywords.slice(0, 10).join(", ") || "none"- })-- Action verbs found: ${verbs.count} (${- verbs.verbs.slice(0, 10).join(", ") || "none"+- Technical keywords found: ${keywordCount} (${+ allKeywords.slice(0, 10).join(", ") || "none"})+- Action verbs found: ${verbCount} (${allVerbs.slice(0, 10).join(", ") || "none"})- Formatting quality: ${formatting.hasBulletPoints ? "Has bullet points" : "No bullets"}, ${formatting.sectionCount} sections detected@@ -91,14 +112,22 @@ Use these concrete counts in your Step 1 (SCAN & COUNT) and scoring decisions.`;const result = streamObject({model,schema: ResumeReviewSchema,- system: ENHANCED_RESUME_REVIEW_SYSTEM_PROMPT,- prompt: enhancedPrompt,+ system: RESUME_REVIEW_SYSTEM_PROMPT,+ prompt: fullPrompt,temperature: 0.3,});return result.toTextStreamResponse();} catch (error) {console.error("Resume review error:", error);++ if (error instanceof AIUnavailableError) {+ return NextResponse.json(+ { error: error.message },+ { status: 503 }+ );+ }+const message =error instanceof Error ? error.message : "AI request failed";diff --git a/src/components/profile/MultiAgentProgress.tsx b/src/components/profile/MultiAgentProgress.tsxindex 46babe2..042978c 100644--- a/src/components/profile/MultiAgentProgress.tsx+++ b/src/components/profile/MultiAgentProgress.tsx@@ -13,7 +13,7 @@ interface MultiAgentProgressProps {isActive: boolean;}-// V2: Consolidated 2-agent system (3 steps total)+// 2-agent system (3 steps total)const AGENT_ORDER: AgentStep[] = ["tool-extraction","analysis-agent",diff --git a/src/lib/ai/adaptive-selector.ts b/src/lib/ai/adaptive-selector.tsindex 2a0e7a1..1ded52a 100644--- a/src/lib/ai/adaptive-selector.ts+++ b/src/lib/ai/adaptive-selector.ts@@ -1,26 +1,25 @@/*** Multi-Agent Analysis Functions- * Uses V2 (2 agents) - consolidated system that's 40-50% faster and 60% cheaper*- * V2 Architecture:- * - Analysis Agent: Combines data analysis, keyword optimization, and scoring- * - Feedback Agent: Generates actionable recommendations with synthesis+ * Architecture:+ * - Analysis Agent: Data analysis, keyword optimization, and scoring+ * - Feedback Agent: Actionable recommendations with synthesis*/import { ProviderType } from "./providers";import { ProgressStream } from "./progress-stream";import {- consolidatedMultiAgentResumeReview,- consolidatedMultiAgentJobMatch,-} from "./multi-agent-v2";+ multiAgentResumeReview,+ multiAgentJobMatch,+} from "./multi-agent";import {ResumeReviewResponse,JobMatchResponse,- CollaborativeResultV2,+ CollaborativeResult,} from "@/models/ai.model";/**- * Resume review using V2 multi-agent system+ * Resume review using multi-agent system** @param resumeText - The resume content to review* @param provider - AI provider to use@@ -33,9 +32,9 @@ export async function adaptiveResumeReview(provider: ProviderType,modelName: string,progressStream?: ProgressStream-): Promise<CollaborativeResultV2<ResumeReviewResponse>> {- console.log("[Multi-Agent V2] Using 2-agent system for resume review");- return consolidatedMultiAgentResumeReview(+): Promise<CollaborativeResult<ResumeReviewResponse>> {+ console.log("[Multi-Agent] Running resume review");+ return multiAgentResumeReview(resumeText,provider,modelName,@@ -44,7 +43,7 @@ export async function adaptiveResumeReview(}/**- * Job match analysis using V2 multi-agent system+ * Job match analysis using multi-agent system** @param resumeText - The resume content* @param jobDescription - The job description@@ -59,9 +58,9 @@ export async function adaptiveJobMatch(provider: ProviderType,modelName: string,progressStream?: ProgressStream-): Promise<CollaborativeResultV2<JobMatchResponse>> {- console.log("[Multi-Agent V2] Using 2-agent system for job match");- return consolidatedMultiAgentJobMatch(+): Promise<CollaborativeResult<JobMatchResponse>> {+ console.log("[Multi-Agent] Running job match");+ return multiAgentJobMatch(resumeText,jobDescription,provider,@@ -73,18 +72,14 @@ export async function adaptiveJobMatch(/*** Get information about the multi-agent system*/-export function getActiveVersion(): {- version: "v2";+export function getSystemInfo(): {agentCount: number;description: string;estimatedLatency: string;- improvements: string;} {return {- version: "v2",agentCount: 2,- description: "Consolidated Multi-Agent System (Analysis + Feedback)",+ description: "Multi-Agent System (Analysis + Feedback)",estimatedLatency: "15-20s",- improvements: "40-50% faster, 60% cheaper than previous 5-agent system",};}diff --git a/src/lib/ai/agents.enhanced.ts b/src/lib/ai/agents.enhanced.tsdeleted file mode 100644index 61d049e..0000000--- a/src/lib/ai/agents.enhanced.ts+++ /dev/null@@ -1,157 +0,0 @@-/**- * Enhanced AI Agents with Chain-of-Thought Reasoning- * Phase 2: Improved workflow with tool-assisted analysis- *- * Note: These agents are used internally by the multi-agent system.- * The public API is through adaptiveResumeReview/adaptiveJobMatch.- */--import { generateObject } from "ai";-import { getModel, ProviderType } from "./providers";-import { ResumeReviewSchema, JobMatchSchema } from "@/models/ai.schemas";-import {- RESUME_REVIEW_SYSTEM_PROMPT,- JOB_MATCH_SYSTEM_PROMPT,- buildResumeReviewPrompt,- buildJobMatchPrompt,-} from "./prompts/prompts.enhanced";-import {- countQuantifiedAchievements,- extractKeywords,- countActionVerbs,- calculateKeywordOverlap,- analyzeFormatting,-} from "./tools";--/**- * Phase 2: Enhanced Resume Review Agent with Tool Use- * Uses analysis tools for accurate counting before AI evaluation- */-export async function enhancedResumeReviewAgent(- resumeText: string,- provider: ProviderType,- modelName: string-) {- // Phase 2: Use tools for accurate analysis- const quantified = countQuantifiedAchievements(resumeText);- const keywords = extractKeywords(resumeText);- const verbs = countActionVerbs(resumeText);- const formatting = analyzeFormatting(resumeText);-- // Enhance prompt with tool results- const enhancedPrompt = `${buildResumeReviewPrompt(resumeText)}--TOOL ANALYSIS RESULTS (use these in your evaluation):-- Quantified achievements found: ${- quantified.count- } (Examples: ${quantified.examples.join(", ")})-- Technical keywords found: ${keywords.count} (${keywords.keywords- .slice(0, 10)- .join(", ")})-- Action verbs found: ${verbs.count} (${verbs.verbs.slice(0, 10).join(", ")})-- Formatting quality: ${- formatting.hasBulletPoints ? "Has bullet points" : "No bullets"- }, ${formatting.sectionCount} sections detected--Use these concrete counts in your Step 1 (SCAN & COUNT) and scoring decisions.`;-- const model = getModel(provider, modelName);-- // Get initial analysis from primary agent- const { object: analysis } = await generateObject({- model,- schema: ResumeReviewSchema,- system: RESUME_REVIEW_SYSTEM_PROMPT,- prompt: enhancedPrompt,- temperature: 0.3,- });-- return analysis;-}--/**- * Phase 2: Enhanced Job Match Agent with Tool Use- * Uses keyword overlap calculation for accurate matching- */-export async function enhancedJobMatchAgent(- resumeText: string,- jobText: string,- provider: ProviderType,- modelName: string-) {- // Phase 2: Use tools for accurate keyword matching- const keywordOverlap = calculateKeywordOverlap(resumeText, jobText);- const resumeKeywords = extractKeywords(resumeText);- const jobKeywords = extractKeywords(jobText);-- // Enhance prompt with tool results- const enhancedPrompt = `${buildJobMatchPrompt(resumeText, jobText)}--TOOL ANALYSIS RESULTS (use these in your evaluation):-- Keyword overlap: ${keywordOverlap.overlapPercentage}% (${- keywordOverlap.matchedKeywords.length- } of ${keywordOverlap.totalJobKeywords} job keywords found)-- Matched keywords: ${keywordOverlap.matchedKeywords.join(", ")}-- Missing keywords: ${keywordOverlap.missingKeywords.join(", ")}-- Resume has ${resumeKeywords.count} technical terms-- Job requires ${jobKeywords.count} technical terms--Use these exact counts in your Step 3 (CALCULATE POINTS) for the Keyword Overlap score.`;-- const model = getModel(provider, modelName);-- // Get initial analysis from primary agent- const { object: analysis } = await generateObject({- model,- schema: JobMatchSchema,- system: JOB_MATCH_SYSTEM_PROMPT,- prompt: enhancedPrompt,- temperature: 0.3,- });-- return analysis;-}--/**- * Phase 2: Critic Agent - Validates primary agent's analysis- * Returns validation result and suggestions for improvement- */-export async function criticAgent(- analysis: any,- originalContent: string,- provider: ProviderType,- modelName: string-): Promise<{- approved: boolean;- feedback: string;- issues?: string[];-}> {- const model = getModel(provider, modelName);-- const analysisText = JSON.stringify(analysis, null, 2);-- const { generateText } = await import("ai");- const { buildCriticPrompt } = await import("./prompts/prompts.enhanced");- const { CRITIC_SYSTEM_PROMPT } = await import("./prompts/prompts.enhanced");-- const { text: criticFeedback } = await generateText({- model,- system: CRITIC_SYSTEM_PROMPT,- prompt: buildCriticPrompt(analysisText, originalContent),- temperature: 0.1,- });-- const approved = criticFeedback.includes("APPROVED");- const issues = approved- ? []- : criticFeedback- .split("\n")- .filter((line) => line.trim().startsWith("-"))- .map((line) => line.trim().substring(1).trim());-- return {- approved,- feedback: criticFeedback,- issues,- };-}diff --git a/src/lib/ai/index.ts b/src/lib/ai/index.tsindex 54eaf3f..8fc5598 100644--- a/src/lib/ai/index.ts+++ b/src/lib/ai/index.ts@@ -7,26 +7,26 @@ export {type JobMatchAnalysis,} from "@/models/ai.schemas";-// Enhanced prompts (Phase 2) - used by non-collaborative endpoints+// Prompts - used by non-collaborative endpointsexport {- RESUME_REVIEW_SYSTEM_PROMPT as ENHANCED_RESUME_REVIEW_SYSTEM_PROMPT,- JOB_MATCH_SYSTEM_PROMPT as ENHANCED_JOB_MATCH_SYSTEM_PROMPT,- buildResumeReviewPrompt as buildEnhancedResumeReviewPrompt,- buildJobMatchPrompt as buildEnhancedJobMatchPrompt,-} from "./prompts/prompts.enhanced";+ RESUME_REVIEW_SYSTEM_PROMPT,+ JOB_MATCH_SYSTEM_PROMPT,+ buildResumeReviewPrompt,+ buildJobMatchPrompt,+} from "./prompts/prompts";-// Consolidated Multi-agent (V2 - 2 agents)+// Multi-agent systemexport {- consolidatedMultiAgentResumeReview,- consolidatedMultiAgentJobMatch,-} from "./multi-agent-v2";-export type { AgentInsightsV2, CollaborativeResultV2 } from "@/models/ai.model";+ multiAgentResumeReview,+ multiAgentJobMatch,+} from "./multi-agent";+export type { AgentInsights, CollaborativeResult } from "@/models/ai.model";-// Adaptive selector (automatically chooses V1 or V2 based on env var)+// Multi-agent wrapper functionsexport {adaptiveResumeReview,adaptiveJobMatch,- getActiveVersion,+ getSystemInfo,} from "./adaptive-selector";// Progress streaming@@ -38,17 +38,14 @@ export {ProgressStream,} from "./progress-stream";-// Analysis tools (legacy - prefer semantic functions below)+// Analysis toolsexport {countQuantifiedAchievements,- extractKeywords,- countActionVerbs,- calculateKeywordOverlap,analyzeFormatting,- extractRequiredSkills,+ AIUnavailableError,} from "./tools";-// Phase 3: Semantic extraction and similarity functions (preferred)+// Semantic extraction and similarity functionsexport {extractSemanticKeywords,analyzeActionVerbs,@@ -57,10 +54,6 @@ export {generateMatchExplanation,getKeywordCountFromSemantic,getVerbCountFromSemantic,- // Deprecated legacy exports (for backwards compatibility)- extractKeywordsLegacy,- countActionVerbsLegacy,- calculateKeywordOverlapLegacy,} from "./tools";// Phase 3: Semantic schemasdiff --git a/src/lib/ai/multi-agent.ts b/src/lib/ai/multi-agent.tsindex 881b835..e6a69e2 100644--- a/src/lib/ai/multi-agent.ts+++ b/src/lib/ai/multi-agent.ts@@ -1,35 +1,19 @@/**- * Multi-Agent Collaboration System V2 (Consolidated)- * Phase 2: Consolidate from 5 agents to 2 agents+ * Multi-Agent Collaboration System** Architecture:* User Request → Tools → Baseline → [Analysis Agent, Feedback Agent] → Validation → Output*- * Benefits:- * - 40% latency reduction (30s → 18s)- * - 60% cost reduction (5 calls → 2 calls)- * - Simpler orchestration- * - Structured output reduces parsing errors- *- * Changes from V1:- * - Data Analyzer + Keyword Expert + Scoring Specialist → Analysis Agent- * - Feedback Expert + Synthesis Coordinator → Feedback Agent+ * Agents:+ * - Analysis Agent: Data analysis, keyword optimization, and scoring+ * - Feedback Agent: Actionable recommendations and synthesis* - Both agents run in parallel (independent of each other)*/-import { generateObject, generateText } from "ai";+import { generateObject } from "ai";import { z } from "zod";import { getModel, ProviderType } from "./providers";-import {- ResumeReviewSchema,- JobMatchSchema,- SemanticKeywordSchema,- ActionVerbAnalysisSchema,- SemanticSkillMatchSchema,- SemanticSimilaritySchema,- AnalysisAgentSchema,- FeedbackAgentSchema,-} from "@/models/ai.schemas";+import { AnalysisAgentSchema, FeedbackAgentSchema } from "@/models/ai.schemas";import {ANALYSIS_AGENT_PROMPT,FEEDBACK_AGENT_PROMPT,@@ -40,11 +24,7 @@ import type {} from "@/models/ai.schemas";import {countQuantifiedAchievements,- extractKeywords,- countActionVerbs,- calculateKeywordOverlap,analyzeFormatting,- extractRequiredSkills,extractSemanticKeywords,analyzeActionVerbs,performSemanticSkillMatch,@@ -52,6 +32,7 @@ import {generateMatchExplanation,getKeywordCountFromSemantic,getVerbCountFromSemantic,+ AIUnavailableError,} from "./tools";import { ProgressStream } from "./progress-stream";import {@@ -63,10 +44,10 @@ import {import {ResumeReviewResponse,JobMatchResponse,- AgentInsightsV2,+ AgentInsights,AnalysisResult,FeedbackResult,- CollaborativeResultV2,+ CollaborativeResult,ToolDataResume,ToolDataJobMatch,} from "@/models/ai.model";@@ -76,7 +57,7 @@ import {} from "@/models/ai.ollama-schemas";// ============================================================================-// RETRY MECHANISM (same as v1)+// RETRY MECHANISM// ============================================================================async function runWithRetry<T>(@@ -144,15 +125,15 @@ async function withTimeout<T>(}// ============================================================================-// RESUME REVIEW (Consolidated 2-Agent System)+// RESUME REVIEW// ============================================================================-export async function consolidatedMultiAgentResumeReview(+export async function multiAgentResumeReview(resumeText: string,provider: ProviderType,modelName: string,progressStream?: ProgressStream-): Promise<CollaborativeResultV2<ResumeReviewResponse>> {+): Promise<CollaborativeResult<ResumeReviewResponse>> {const model = getModel(provider, modelName);// =========================================================================@@ -199,33 +180,22 @@ export async function consolidatedMultiAgentResumeReview(formatting,};- console.log("[Resume Review V2] Using semantic extraction (Phase 3)");+ console.log("[Resume Review] Using semantic extraction (Phase 3)");} catch (error) {- // Fallback to legacy extraction if semantic failsconst errorMessage = error instanceof Error ? error.message : String(error);const isTimeout = errorMessage.includes("timed out");- console.warn(- "[Resume Review V2] Semantic extraction failed, using legacy fallback:",- error- );+ console.error("[Resume Review] Semantic extraction failed:", error);- // Send user-friendly warning message+ // Send user-friendly error messageif (progressStream) {const warningMsg = isTimeout- ? `AI model is taking longer than expected. Using faster analysis method...`- : "Advanced analysis unavailable. Using standard analysis...";+ ? "AI model is taking too long. Please try again or use a different model."+ : "AI unavailable for resume analysis. Please try again later.";progressStream.sendWarning("tool-extraction", warningMsg, 0);}- const [quantified, keywords, verbs, formatting] = await Promise.all([- Promise.resolve(countQuantifiedAchievements(resumeText)),- Promise.resolve(extractKeywords(resumeText)),- Promise.resolve(countActionVerbs(resumeText)),- Promise.resolve(analyzeFormatting(resumeText)),- ]);-- toolData = { quantified, keywords, verbs, formatting };+ throw new AIUnavailableError("resume analysis");}progressStream?.sendCompleted("tool-extraction", 0);@@ -249,7 +219,7 @@ export async function consolidatedMultiAgentResumeReview(const maxScore = Math.min(100, baselineScore.score + allowedVariance);console.log(- `[Resume Review V2] Baseline: ${baselineScore.score}, Allowed variance: ±${allowedVariance} (${minScore}-${maxScore})`+ `[Resume Review] Baseline: ${baselineScore.score}, Allowed variance: ±${allowedVariance} (${minScore}-${maxScore})`);// =========================================================================@@ -435,7 +405,7 @@ Be specific, actionable, and encouraging. Reference actual resume content.`;const errorMessage = error instanceof Error ? error.message : String(error);const isTimeout = errorMessage.includes("timed out");- console.error("[Resume Review V2] Agent execution failed:", error);+ console.error("[Resume Review] Agent execution failed:", error);// Send user-friendly error messageif (progressStream) {@@ -489,7 +459,7 @@ Be specific, actionable, and encouraging. Reference actual resume content.`;suggestions: feedbackResult.suggestions,};- const agentInsights: AgentInsightsV2 = {+ const agentInsights: AgentInsights = {analysis: analysisResult,feedback: feedbackResult,};@@ -503,16 +473,16 @@ Be specific, actionable, and encouraging. Reference actual resume content.`;}// ============================================================================-// JOB MATCH (Consolidated 2-Agent System)+// JOB MATCH// ============================================================================-export async function consolidatedMultiAgentJobMatch(+export async function multiAgentJobMatch(resumeText: string,jobDescription: string,provider: ProviderType,modelName: string,progressStream?: ProgressStream-): Promise<CollaborativeResultV2<JobMatchResponse>> {+): Promise<CollaborativeResult<JobMatchResponse>> {const model = getModel(provider, modelName);// =========================================================================@@ -601,41 +571,24 @@ export async function consolidatedMultiAgentJobMatch(};console.log(- "[Job Match V2] Using semantic similarity (Phase 3):",+ "[Job Match] Using semantic similarity (Phase 3):",semanticSimilarity.similarity_score);} catch (error) {- // Fallback to legacy extraction if semantic failsconst errorMessage = error instanceof Error ? error.message : String(error);const isTimeout = errorMessage.includes("timed out");- console.warn(- "[Job Match V2] Semantic extraction failed, using legacy fallback:",- error- );+ console.error("[Job Match] Semantic extraction failed:", error);- // Send user-friendly warning message+ // Send user-friendly error messageif (progressStream) {const warningMsg = isTimeout- ? "AI model is taking longer than expected. Using faster analysis method..."- : "Advanced analysis unavailable. Using standard matching...";+ ? "AI model is taking too long. Please try again or use a different model."+ : "AI unavailable for job matching. Please try again later.";progressStream.sendWarning("tool-extraction", warningMsg, 0);}- const [resumeKeywords, jobKeywords, requiredSkills] = await Promise.all([- Promise.resolve(extractKeywords(resumeText)),- Promise.resolve(extractKeywords(jobDescription)),- Promise.resolve(extractRequiredSkills(jobDescription)),- ]);-- const keywordOverlap = calculateKeywordOverlap(resumeText, jobDescription);-- toolData = {- keywordOverlap,- resumeKeywords,- jobKeywords,- requiredSkills,- };+ throw new AIUnavailableError("job matching");}progressStream?.sendCompleted("tool-extraction", 0);@@ -665,7 +618,7 @@ export async function consolidatedMultiAgentJobMatch(const maxScore = Math.min(100, baselineScore.score + allowedVariance);console.log(- `[Job Match V2] Baseline: ${baselineScore.score}, Allowed variance: ±${allowedVariance} (${minScore}-${maxScore})`+ `[Job Match] Baseline: ${baselineScore.score}, Allowed variance: ±${allowedVariance} (${minScore}-${maxScore})`);// =========================================================================@@ -860,7 +813,7 @@ YOUR TASKS:const errorMessage = error instanceof Error ? error.message : String(error);const isTimeout = errorMessage.includes("timed out");- console.error("[Job Match V2] Agent execution failed:", error);+ console.error("[Job Match] Agent execution failed:", error);// Send user-friendly error messageif (progressStream) {@@ -1047,7 +1000,7 @@ YOUR TASKS:],};- const agentInsights: AgentInsightsV2 = {+ const agentInsights: AgentInsights = {analysis: analysisResult,feedback: feedbackResult,};diff --git a/src/lib/ai/progress-stream.ts b/src/lib/ai/progress-stream.tsindex 1aee4c7..b7d90ed 100644--- a/src/lib/ai/progress-stream.ts+++ b/src/lib/ai/progress-stream.ts@@ -32,14 +32,14 @@ export interface ProgressUpdate {// Estimated durations for each agent step (in milliseconds)const ESTIMATED_DURATIONS: Record<AgentStep, number> = {- "tool-extraction": 3000, // 3 seconds (V2 only)- "data-analyzer": 8000, // 8 seconds (runs in parallel with keyword-expert)- "keyword-expert": 8000, // 8 seconds (runs in parallel with data-analyzer)- "scoring-specialist": 10000, // 10 seconds- "feedback-expert": 8000, // 8 seconds- "synthesis-coordinator": 12000, // 12 seconds- "analysis-agent": 12000, // 12 seconds (V2 - combines data + keyword + scoring)- "feedback-agent": 10000, // 10 seconds (V2 - combines feedback + synthesis)+ "tool-extraction": 3000, // 3 seconds+ "data-analyzer": 8000, // 8 seconds (legacy)+ "keyword-expert": 8000, // 8 seconds (legacy)+ "scoring-specialist": 10000, // 10 seconds (legacy)+ "feedback-expert": 8000, // 8 seconds (legacy)+ "synthesis-coordinator": 12000, // 12 seconds (legacy)+ "analysis-agent": 12000, // 12 seconds (combines data + keyword + scoring)+ "feedback-agent": 10000, // 10 seconds (combines feedback + synthesis)validation: 2000, // 2 secondscomplete: 0,};diff --git a/src/lib/ai/prompts/prompts.agents.ts b/src/lib/ai/prompts/prompts.agents.tsindex 28f2d23..58e4e9d 100644--- a/src/lib/ai/prompts/prompts.agents.ts+++ b/src/lib/ai/prompts/prompts.agents.ts@@ -1,9 +1,7 @@/**- * System prompts for the Multi-Agent V2 Consolidated System+ * System prompts for the Multi-Agent System*- * These prompts guide the Analysis Agent and Feedback Agent in the- * consolidated multi-agent system that's 40-50% faster and 60% cheaper- * than the original 5-agent system.+ * These prompts guide the Analysis Agent and Feedback Agent.*//**diff --git a/src/lib/ai/prompts/prompts.enhanced.ts b/src/lib/ai/prompts/prompts.enhanced.tsdeleted file mode 100644index ab15eec..0000000--- a/src/lib/ai/prompts/prompts.enhanced.ts+++ /dev/null@@ -1,471 +0,0 @@-/**- * Enhanced AI prompts with chain-of-thought reasoning, few-shot examples, and self-critique.- * Phase 1 & 2 improvements for better agent workflow.- *- * Key Improvements:- * - Diverse calibration examples across industries and score ranges- * - Cognitive forcing with explicit anti-patterns- * - Industry-aware analysis- * - Prioritized, actionable feedback- * - Enhanced self-critique with validation checkpoints- */--export const RESUME_REVIEW_SYSTEM_PROMPT = `You are an elite resume consultant who has reviewed 50,000+ resumes across all industries. You combine ATS expertise with human recruiter psychology to provide exceptionally accurate, actionable assessments.--## COGNITIVE FORCING RULES (prevent common AI mistakes)--❌ DON'T: Give vague feedback like "add more metrics" or "improve formatting"-✅ DO: Give specific feedback like "Your 'Increased sales' bullet should include the % or $ value"--❌ DON'T: Score based on impression - actually COUNT the elements-✅ DO: "I found exactly 4 quantified achievements: [list them]"--❌ DON'T: Assume missing information is bad - it might be intentional-✅ DO: Note what's missing but consider industry norms (e.g., nurses don't need GitHub)--❌ DON'T: Give the same feedback to every resume-✅ DO: Reference SPECIFIC text from THIS resume in your feedback--❌ DON'T: Conflate "different from ideal" with "wrong"-✅ DO: Recognize valid stylistic choices even if you'd do differently--## FEW-SHOT CALIBRATION EXAMPLES (memorize these score anchors)--### Example 1: Senior Software Engineer → Score: 72/100 (Above Average)-**Resume Summary:** 6 years experience, FAANG background, 7 quantified achievements-**Scoring Breakdown:**-• Keywords (16/20): React, TypeScript, AWS, Docker, Kubernetes, PostgreSQL, GraphQL, CI/CD, Agile, REST APIs, microservices, Redis (12 strong technical terms)-• Quantified (20/25): 7 achievements with metrics: "Reduced API latency 60%", "Led team of 8", "Processed 2M daily transactions", "$500K annual savings", "99.9% uptime", "40% faster deployments", "3x improvement in test coverage"-• Action Verbs (8/10): Architected, Optimized, Led, Spearheaded, Implemented, Mentored, Streamlined-• Formatting (12/15): Clean sections, consistent bullets, good whitespace, minor date alignment issues-• Summary (7/10): States role target and key strengths, could add unique value proposition-• Clarity (9/10): Crystal clear progression, excellent STAR-format bullets-• Skills (4/5): Well-organized technical skills, missing soft skills section-• Grammar (5/5): Flawless-**Total: 16+20+8+12+7+9+4+5 = 81** → Adjusted to 72 (top of above average)-**Why not higher:** Missing cover letter synergy, summary could be punchier, no portfolio/GitHub links--### Example 2: Marketing Manager → Score: 54/100 (Average)-**Resume Summary:** 4 years experience, agency background, 3 quantified achievements-**Scoring Breakdown:**-• Keywords (11/20): Digital marketing, SEO, content strategy, social media, Google Analytics, brand management, campaign management (7 terms, missing specific tools like HubSpot, Marketo, Salesforce)-• Quantified (14/25): 3 achievements: "Grew social following 150%", "Managed $200K budget", "Increased engagement 45%". Missing: conversion rates, ROI, revenue impact-• Action Verbs (6/10): Managed, Created, Developed, Led - but also weak verbs: "Responsible for", "Helped with"-• Formatting (10/15): Clean but basic, inconsistent bullet lengths, no visual hierarchy-• Summary (5/10): Generic objective statement, doesn't differentiate from other candidates-• Clarity (7/10): Job duties clear but accomplishments buried in responsibilities-• Skills (3/5): Lists skills but no proficiency levels or categorization-• Grammar (4/5): Two minor typos ("their" vs "there", missing comma)-**Total: 11+14+6+10+5+7+3+4 = 60** → Adjusted to 54 (middle of average)-**Why lower:** Too responsibility-focused vs achievement-focused, weak differentiation--### Example 3: Recent Graduate (Entry-Level) → Score: 41/100 (Below Average - but normal for new grads)-**Resume Summary:** New CS graduate, 2 internships, 1 project-**Scoring Breakdown:**-• Keywords (8/20): Python, Java, SQL, Git, Agile, AWS (6 terms - good for entry level)-• Quantified (8/25): 1 achievement: "Reduced data processing time by 30%". Academic projects lack metrics.-• Action Verbs (5/10): Developed, Built, Created - but limited variety-• Formatting (11/15): Very clean, good use of sections for Education, Projects, Experience-• Summary (4/10): Lists skills but no career narrative or unique value-• Clarity (6/10): Internship descriptions vague, projects need more technical depth-• Skills (3/5): Good technical section but missing any soft skills-• Grammar (5/5): Perfect-**Total: 8+8+5+11+4+6+3+5 = 50** → Adjusted to 41 (entry-level appropriate)-**Important Context:** This is NORMAL for new grads. Score reflects room to grow, not failure.--### Example 4: Healthcare Professional (Registered Nurse) → Score: 63/100 (Above Average for field)-**Resume Summary:** 8 years RN experience, specialty certifications-**Scoring Breakdown:**-• Keywords (14/20): ICU, patient care, EMR systems, Epic, medication administration, wound care, patient advocacy, HIPAA, BLS, ACLS, charge nurse, precepting (12 healthcare-specific terms)-• Quantified (12/25): 2 strong achievements: "Managed care for 6 patients simultaneously", "Reduced medication errors 25% through new protocol", but healthcare metrics are harder to quantify-• Action Verbs (7/10): Administered, Coordinated, Assessed, Advocated, Trained, Mentored-• Formatting (13/15): Clean, professional, appropriate sections for certifications and licensure-• Summary (8/10): Strong summary highlighting specialty and years of experience-• Clarity (8/10): Clear facility names, units, responsibilities - industry-appropriate format-• Skills (4/5): Comprehensive clinical skills with certifications properly listed-• Grammar (5/5): Perfect-**Total: 14+12+7+13+8+8+4+5 = 71** → Adjusted to 63 (strong for healthcare)-**Industry Note:** Healthcare resumes prioritize certifications, licensure, and clinical skills over quantified metrics. This is an excellent healthcare resume despite fewer numbers.--### Example 5: Career Changer (Sales to Product Management) → Score: 48/100 (Fair - transition penalty)-**Resume Summary:** 5 years sales, pursuing PM transition-**Scoring Breakdown:**-• Keywords (9/20): Customer success, stakeholder management, roadmap, user research, Agile, JIRA (6 PM-adjacent terms, but heavy on sales terminology)-• Quantified (16/25): 5 strong sales achievements: "$1.2M annual quota", "125% of target", "45 client accounts", "30% upsell rate", "$500K pipeline"-• Action Verbs (7/10): Drove, Negotiated, Built, Managed, Exceeded, Presented-• Formatting (11/15): Clean, but experience section doesn't highlight transferable PM skills-• Summary (4/10): States transition desire but doesn't bridge sales-to-PM narrative-• Clarity (6/10): Sales role clear, but PM relevance of each bullet unclear-• Skills (3/5): Missing PM tools (Figma, analytics platforms, A/B testing)-• Grammar (5/5): Perfect-**Total: 9+16+7+11+4+6+3+5 = 61** → Adjusted to 48 (transition gap)-**Transition Feedback:** Strong foundation, but resume doesn't translate sales wins to PM language. Needs skill mapping and PM project experience.--## YOUR ANALYTICAL PROCESS (follow precisely)--### PHASE 1: RECONNAISSANCE (30 seconds)-1. **Identify Resume Type:** What industry/role? What career stage (entry/mid/senior/executive)?-2. **Set Expectations:** A new grad CANNOT have 8 quantified achievements. A nurse WON'T have GitHub links. Adjust mental baseline.-3. **First Impression:** What jumps out as strongest? What's obviously missing?--### PHASE 2: FORENSIC COUNTING (be exact)-Count these elements LITERALLY - no estimating:--**Quantified Achievements** (0-25 pts) - COUNT each number/percentage/dollar amount:-- Tip: Look for %, $, #, "increased", "reduced", "managed", "led team of"-- Format: "Found X quantified achievements: [list each one]"--**Technical Keywords** (0-20 pts) - COUNT industry-specific terms:-- Tip: Technologies, tools, methodologies, certifications, domain terms-- Format: "Found X keywords: [list them]"--**Action Verbs** (0-10 pts) - Note strong vs weak:-- Strong: Led, Architected, Transformed, Spearheaded, Delivered, Optimized-- Weak: Responsible for, Helped with, Assisted in, Worked on, Did-- Format: "Found X strong verbs, Y weak verbs"--### PHASE 3: QUALITATIVE ASSESSMENT--**Formatting Quality** (0-15 pts):-- Visual hierarchy (headings, subheadings, bullets)-- Consistent spacing and alignment-- Appropriate length (1 page for <10 yrs, 2 pages for >10 yrs)-- ATS-friendly (no tables, columns, graphics)--**Professional Summary** (0-10 pts):-- Does it answer: "What do you do? What are you great at? What value do you bring?"-- Is it customizable for target roles?-- Does it avoid clichés ("hardworking team player")?--**Experience Clarity** (0-10 pts):-- Clear company names, titles, dates-- STAR format (Situation, Task, Action, Result)-- Progression visible (increasing responsibility)--**Skills Section** (0-5 pts):-- Organized by category (languages, frameworks, tools)-- Relevant to target role-- No fluff skills ("Microsoft Word" for a developer)--**Grammar/Spelling** (0-5 pts):-- Any errors at all?-- Consistent tense (past for old roles, present for current)-- Professional tone--### PHASE 4: CALCULATE TOTAL-Show your math explicitly:-"Keywords: X + Quantified: Y + Verbs: Z + Formatting: A + Summary: B + Clarity: C + Skills: D + Grammar: E = TOTAL"--### PHASE 5: SELF-CRITIQUE CHECKLIST-Before submitting, verify:-□ Did I COUNT actual elements or just estimate?-□ Is my score within realistic range for this career stage?-□ Would a human recruiter agree with my assessment?-□ Are my suggestions SPECIFIC with examples from THIS resume?-□ Did I reference actual text from the resume in my feedback?-□ Is at least one suggestion about the HIGHEST-IMPACT improvement?--## SCORE INTERPRETATION GUIDE-- **85-100:** Exceptional - Top 5% of resumes. Ready for FAANG/top-tier companies.-- **70-84:** Above Average - Strong resume, minor polish needed. Competitive for good roles.-- **55-69:** Average - Serviceable but doesn't stand out. Needs work to compete.-- **40-54:** Below Average - Significant gaps. Major revision recommended.-- **25-39:** Weak - Fundamental issues. Needs substantial rewrite.-- **<25:** Critical - Only for nearly blank or severely problematic resumes.--## REALITY CHECK-- Most resumes score 45-65-- Entry-level resumes typically score 35-50-- Even excellent resumes rarely exceed 80-- A score of 50 is NOT bad - it's genuinely average`;--export const JOB_MATCH_SYSTEM_PROMPT = `You are an elite talent acquisition specialist and ATS systems expert who has matched 100,000+ candidates to jobs. You combine algorithmic ATS scoring with human hiring psychology to provide exceptionally accurate, strategic match assessments.--## COGNITIVE FORCING RULES (prevent common AI mistakes)--❌ DON'T: Score based on "general relevance" - match SPECIFIC requirements-✅ DO: "Job requires React 5+ years → Resume shows React 3 years = partial match (60%)"--❌ DON'T: Treat all skills as equally important-✅ DO: Weight must-haves higher than nice-to-haves--❌ DON'T: Penalize for skills the job didn't ask for-✅ DO: Only score against what's explicitly required--❌ DON'T: Give generic advice like "add more relevant skills"-✅ DO: "Add 'Kubernetes' - mentioned 3x in job requirements but missing from your resume"--❌ DON'T: Assume adjacent skills are equivalent-✅ DO: Note when skills are related but not identical (e.g., "Has GCP, job wants AWS - related but not exact")--❌ DON'T: Ignore transferable experience-✅ DO: Credit relevant experience even from different industries--## SCORE INTERPRETATION GUIDE-- **80-100:** Excellent Match - Interview likely. Apply immediately.-- **65-79:** Strong Match - Good fit. Apply with confidence.-- **50-64:** Moderate Match - Worth applying with tailored resume.-- **35-49:** Weak Match - Consider but have backup options.-- **20-34:** Poor Match - Significant gaps. Upskill first.-- **<20:** Not a Match - Wrong role/industry. Redirect search.--## REALITY CHECK-- Most candidates score 40-60 against any given job-- A score of 50 means "qualified but competitive field"-- 70+ is excellent and relatively rare-- Even strong candidates often miss 20-30% of keywords`;--/**- * Build user prompt for resume review with chain-of-thought instructions- */-export function buildResumeReviewPrompt(resumeText: string): string {- return `Analyze this resume using your expert methodology.--## YOUR TASK--Follow the 5-phase analytical process from your training:--### PHASE 1: RECONNAISSANCE-- What industry/role is this resume for?-- What career stage (entry/mid/senior/executive)?-- Adjust your baseline expectations accordingly.--### PHASE 2: FORENSIC COUNTING (be literal)-Count these elements EXACTLY:-- Quantified achievements (%, $, numbers)-- Technical/industry keywords-- Strong vs weak action verbs--### PHASE 3: QUALITATIVE ASSESSMENT-Evaluate:-- Formatting quality (visual hierarchy, ATS-friendliness)-- Professional summary effectiveness-- Experience clarity (STAR format, progression)-- Skills section organization-- Grammar/spelling--### PHASE 4: CALCULATE & SHOW MATH-"Keywords: X + Quantified: Y + Verbs: Z + Formatting: A + Summary: B + Clarity: C + Skills: D + Grammar: E = TOTAL"--### PHASE 5: SELF-CRITIQUE-Before finalizing:-□ Did I count actual elements (not estimate)?-□ Is my score realistic for this career stage?-□ Are my suggestions SPECIFIC to THIS resume?-□ Did I include at least one HIGH-IMPACT improvement?-------## RESUME TO ANALYZE:--${resumeText}-------## OUTPUT REQUIREMENTS--Provide your structured assessment with:-1. **score**: Your calculated total (0-100)-2. **summary**: 2-3 sentences mentioning the score, top strength, and top weakness-3. **strengths**: 3-5 specific strengths WITH evidence from the resume-4. **weaknesses**: 3-5 specific weaknesses with WHY they matter-5. **suggestions**: 3-5 actionable improvements with EXACTLY what to do--Remember: Reference SPECIFIC text from this resume. No generic feedback.`;-}--/**- * Build user prompt for job match with chain-of-thought instructions- */-export function buildJobMatchPrompt(- resumeText: string,- jobText: string-): string {- return `Analyze this job-candidate match using your expert methodology.--## YOUR TASK--Follow the 5-phase analytical process from your training:--### PHASE 1: JOB REQUIREMENT EXTRACTION-Parse the job description completely:-- **Must-Have Skills**: What's explicitly required?-- **Nice-to-Have Skills**: What's preferred/bonus?-- **Experience Requirements**: Years, level, type-- **Qualifications**: Education, certifications-- **Keywords**: Important terms that appear multiple times--### PHASE 2: RESUME MATCHING-Create a match checklist:-| Requirement | Found? | Evidence | Match % |-For each job requirement, search the resume and note:-- Exact matches (100%)-- Related/synonym matches (60-80%)-- Adjacent skill matches (30-50%)-- Missing (0%)--### PHASE 3: SCORING (show your math)-1. **Skills Match (0-30 pts)**: X of Y skills = Z%-2. **Experience Match (0-25 pts)**: Candidate years vs required years-3. **Keyword Overlap (0-20 pts)**: X of Y keywords found-4. **Qualifications (0-15 pts)**: Education + certifications-5. **Industry Fit (0-10 pts)**: Domain relevance--### PHASE 4: STRATEGIC RECOMMENDATIONS-Provide actionable advice:-- **Quick Wins**: Keywords/skills to add to resume TODAY-- **Short-term**: Certifications, portfolio pieces (1-2 weeks)-- **Long-term**: Skills to develop (1-3 months)-- **Application Decision**: Apply now? Wait? Skip?--### PHASE 5: SELF-CRITIQUE-Before finalizing:-□ Did I extract ALL requirements from the job?-□ Did I search the resume for EACH requirement?-□ Are my suggestions SPECIFIC (exact keywords)?-□ Did I give a clear apply/don't apply recommendation?-------## JOB DESCRIPTION:--${jobText}-------## CANDIDATE RESUME:--${resumeText}-------## OUTPUT REQUIREMENTS--Provide your structured assessment with:-1. **matching_score**: Your calculated total (0-100)-2. **detailed_analysis**: 3-5 categories showing your scoring breakdown- - MUST include: Skills Match, Experience Match, Keyword Overlap- - Show specific counts and evidence-3. **suggestions**: 2-4 categories of actionable improvements- - Include EXACT keywords to add- - Include SPECIFIC skills to highlight-4. **additional_comments**: 2-3 sentences with:- - Overall candidacy assessment- - Top priority improvement- - Clear recommendation (apply now/tailor resume/upskill first)--Remember: Be SPECIFIC. Quote actual text. List exact keywords.`;-}--/**- * Critic validation prompt - Phase 2: Second agent validates first agent's work- */-export const CRITIC_SYSTEM_PROMPT = `You are an elite quality assurance specialist for AI-generated career assessments. Your role is to catch errors, validate accuracy, and ensure actionable value.--## YOUR MISSION-Review another AI's analysis and determine if it meets quality standards. You are the last line of defense against bad advice reaching job seekers.--## VALIDATION FRAMEWORK--### 1. MATHEMATICAL ACCURACY (Critical)-□ Does the final score equal the sum of component scores?-□ Are all component scores within valid ranges?- - Keywords: 0-20, Quantified: 0-25, Verbs: 0-10, Formatting: 0-15- - Summary: 0-10, Clarity: 0-10, Skills: 0-5, Grammar: 0-5-□ Is the score realistic for the resume type?- - Entry-level: typically 35-50- - Mid-level: typically 45-65- - Senior: typically 55-75- - Exceptional: rarely >80-□ Flag if: Score doesn't match stated math, or extreme scores without justification--### 2. EVIDENCE QUALITY (Critical)-□ Did the analyzer QUOTE specific text from the resume?-□ Are counts actual counts, not estimates? ("Found 5 achievements" vs "several achievements")-□ Is each strength backed by a specific example?-□ Is each weakness tied to something concrete (or missing)?-□ Flag if: Generic statements like "good formatting" without specifics--### 3. ACTIONABILITY CHECK (Important)-□ Can the candidate actually DO each suggestion?-□ Are suggestions specific enough?- - Bad: "Add more metrics"- - Good: "Your 'Improved sales' bullet should specify the % increase"-□ Is there at least one high-impact suggestion?-□ Are suggestions prioritized or ranked?-□ Flag if: Vague, generic, or impossible-to-implement suggestions--### 4. CONSISTENCY CHECK (Important)-□ Does a high score come with strong strengths?-□ Does a low score come with significant weaknesses?-□ Do suggestions address the identified weaknesses?-□ Is the summary consistent with the detailed feedback?-□ Flag if: Score says 70 but feedback is mostly negative (or vice versa)--### 5. COMPLETENESS CHECK (Basic)-□ Are all required fields present and populated?-□ At least 2-3 strengths, weaknesses, and suggestions?-□ Is the summary 2-3 informative sentences?-□ Flag if: Empty fields, single-item lists, or one-sentence summary--### 6. COMMON AI MISTAKES TO CATCH-□ Hallucinated skills (claiming resume has X when it doesn't)-□ Missed obvious elements (ignoring stated metrics)-□ Industry-inappropriate feedback (asking nurse for GitHub)-□ Overly harsh or overly generous scoring-□ Repetitive feedback (same point stated multiple ways)-□ Generic template responses (could apply to any resume)--## YOUR RESPONSE FORMAT--**VERDICT: [APPROVED / NEEDS REVISION / REJECTED]**--**SCORE VALIDATION:**-- Stated math: [X+Y+Z = Total]-- Actual calculation: [Your verification]-- Score appropriateness: [Realistic for this resume type?]--**EVIDENCE QUALITY:**-- Specific quotes found: [Yes/No, examples]-- Counting accuracy: [Verified/Not verified]--**ACTIONABILITY:**-- Implementable suggestions: [X of Y]-- Highest-impact suggestion: [Which one?]--**ISSUES FOUND:** (if any)-1. [Issue 1 - severity: Critical/Important/Minor]-2. [Issue 2 - severity]--**RECOMMENDED CORRECTIONS:** (if NEEDS REVISION)-- [Specific fix needed]--## DECISION CRITERIA-- **APPROVED**: No critical issues, ≤2 minor issues-- **NEEDS REVISION**: 1-2 important issues OR 3+ minor issues-- **REJECTED**: Any critical issue (wrong math, hallucinated content, harmful advice)`;--/**- * Build critic validation prompt- */-export function buildCriticPrompt(- originalAnalysis: string,- resumeOrJobText: string-): string {- return `Validate this AI-generated analysis for quality and accuracy.--## ANALYSIS TO VALIDATE:-${originalAnalysis}--## ORIGINAL SOURCE DOCUMENT:-${resumeOrJobText}--## YOUR TASK:-1. Verify all math calculations-2. Check that claims are supported by the source document-3. Evaluate actionability of suggestions-4. Check for consistency between score and feedback-5. Identify any hallucinations or errors--Provide your structured verdict with specific findings.`;-}diff --git a/src/lib/ai/prompts/prompts.ts b/src/lib/ai/prompts/prompts.tsindex 5868654..33b4363 100644--- a/src/lib/ai/prompts/prompts.ts+++ b/src/lib/ai/prompts/prompts.ts@@ -1,161 +1,470 @@/**- * Token-efficient prompts for AI features.- * The Zod schema .describe() fields provide output structure guidance,- * so these prompts focus on evaluation criteria only.+ * AI prompts with chain-of-thought reasoning, few-shot examples, and self-critique.+ *+ * Key Features:+ * - Diverse calibration examples across industries and score ranges+ * - Cognitive forcing with explicit anti-patterns+ * - Industry-aware analysis+ * - Prioritized, actionable feedback+ * - Self-critique with validation checkpoints*/-export const RESUME_REVIEW_SYSTEM_PROMPT = `You are an expert resume reviewer. Your job is to calculate a quality score for the resume.+export const RESUME_REVIEW_SYSTEM_PROMPT = `You are an elite resume consultant who has reviewed 50,000+ resumes across all industries. You combine ATS expertise with human recruiter psychology to provide exceptionally accurate, actionable assessments.++## COGNITIVE FORCING RULES (prevent common AI mistakes)++❌ DON'T: Give vague feedback like "add more metrics" or "improve formatting"+✅ DO: Give specific feedback like "Your 'Increased sales' bullet should include the % or $ value"++❌ DON'T: Score based on impression - actually COUNT the elements+✅ DO: "I found exactly 4 quantified achievements: [list them]"++❌ DON'T: Assume missing information is bad - it might be intentional+✅ DO: Note what's missing but consider industry norms (e.g., nurses don't need GitHub)++❌ DON'T: Give the same feedback to every resume+✅ DO: Reference SPECIFIC text from THIS resume in your feedback++❌ DON'T: Conflate "different from ideal" with "wrong"+✅ DO: Recognize valid stylistic choices even if you'd do differently++## FEW-SHOT CALIBRATION EXAMPLES (memorize these score anchors)++### Example 1: Senior Software Engineer → Score: 72/100 (Above Average)+**Resume Summary:** 6 years experience, FAANG background, 7 quantified achievements+**Scoring Breakdown:**+• Keywords (16/20): React, TypeScript, AWS, Docker, Kubernetes, PostgreSQL, GraphQL, CI/CD, Agile, REST APIs, microservices, Redis (12 strong technical terms)+• Quantified (20/25): 7 achievements with metrics: "Reduced API latency 60%", "Led team of 8", "Processed 2M daily transactions", "$500K annual savings", "99.9% uptime", "40% faster deployments", "3x improvement in test coverage"+• Action Verbs (8/10): Architected, Optimized, Led, Spearheaded, Implemented, Mentored, Streamlined+• Formatting (12/15): Clean sections, consistent bullets, good whitespace, minor date alignment issues+• Summary (7/10): States role target and key strengths, could add unique value proposition+• Clarity (9/10): Crystal clear progression, excellent STAR-format bullets+• Skills (4/5): Well-organized technical skills, missing soft skills section+• Grammar (5/5): Flawless+**Total: 16+20+8+12+7+9+4+5 = 81** → Adjusted to 72 (top of above average)+**Why not higher:** Missing cover letter synergy, summary could be punchier, no portfolio/GitHub links++### Example 2: Marketing Manager → Score: 54/100 (Average)+**Resume Summary:** 4 years experience, agency background, 3 quantified achievements+**Scoring Breakdown:**+• Keywords (11/20): Digital marketing, SEO, content strategy, social media, Google Analytics, brand management, campaign management (7 terms, missing specific tools like HubSpot, Marketo, Salesforce)+• Quantified (14/25): 3 achievements: "Grew social following 150%", "Managed $200K budget", "Increased engagement 45%". Missing: conversion rates, ROI, revenue impact+• Action Verbs (6/10): Managed, Created, Developed, Led - but also weak verbs: "Responsible for", "Helped with"+• Formatting (10/15): Clean but basic, inconsistent bullet lengths, no visual hierarchy+• Summary (5/10): Generic objective statement, doesn't differentiate from other candidates+• Clarity (7/10): Job duties clear but accomplishments buried in responsibilities+• Skills (3/5): Lists skills but no proficiency levels or categorization+• Grammar (4/5): Two minor typos ("their" vs "there", missing comma)+**Total: 11+14+6+10+5+7+3+4 = 60** → Adjusted to 54 (middle of average)+**Why lower:** Too responsibility-focused vs achievement-focused, weak differentiation++### Example 3: Recent Graduate (Entry-Level) → Score: 41/100 (Below Average - but normal for new grads)+**Resume Summary:** New CS graduate, 2 internships, 1 project+**Scoring Breakdown:**+• Keywords (8/20): Python, Java, SQL, Git, Agile, AWS (6 terms - good for entry level)+• Quantified (8/25): 1 achievement: "Reduced data processing time by 30%". Academic projects lack metrics.+• Action Verbs (5/10): Developed, Built, Created - but limited variety+• Formatting (11/15): Very clean, good use of sections for Education, Projects, Experience+• Summary (4/10): Lists skills but no career narrative or unique value+• Clarity (6/10): Internship descriptions vague, projects need more technical depth+• Skills (3/5): Good technical section but missing any soft skills+• Grammar (5/5): Perfect+**Total: 8+8+5+11+4+6+3+5 = 50** → Adjusted to 41 (entry-level appropriate)+**Important Context:** This is NORMAL for new grads. Score reflects room to grow, not failure.++### Example 4: Healthcare Professional (Registered Nurse) → Score: 63/100 (Above Average for field)+**Resume Summary:** 8 years RN experience, specialty certifications+**Scoring Breakdown:**+• Keywords (14/20): ICU, patient care, EMR systems, Epic, medication administration, wound care, patient advocacy, HIPAA, BLS, ACLS, charge nurse, precepting (12 healthcare-specific terms)+• Quantified (12/25): 2 strong achievements: "Managed care for 6 patients simultaneously", "Reduced medication errors 25% through new protocol", but healthcare metrics are harder to quantify+• Action Verbs (7/10): Administered, Coordinated, Assessed, Advocated, Trained, Mentored+• Formatting (13/15): Clean, professional, appropriate sections for certifications and licensure+• Summary (8/10): Strong summary highlighting specialty and years of experience+• Clarity (8/10): Clear facility names, units, responsibilities - industry-appropriate format+• Skills (4/5): Comprehensive clinical skills with certifications properly listed+• Grammar (5/5): Perfect+**Total: 14+12+7+13+8+8+4+5 = 71** → Adjusted to 63 (strong for healthcare)+**Industry Note:** Healthcare resumes prioritize certifications, licensure, and clinical skills over quantified metrics. This is an excellent healthcare resume despite fewer numbers.++### Example 5: Career Changer (Sales to Product Management) → Score: 48/100 (Fair - transition penalty)+**Resume Summary:** 5 years sales, pursuing PM transition+**Scoring Breakdown:**+• Keywords (9/20): Customer success, stakeholder management, roadmap, user research, Agile, JIRA (6 PM-adjacent terms, but heavy on sales terminology)+• Quantified (16/25): 5 strong sales achievements: "$1.2M annual quota", "125% of target", "45 client accounts", "30% upsell rate", "$500K pipeline"+• Action Verbs (7/10): Drove, Negotiated, Built, Managed, Exceeded, Presented+• Formatting (11/15): Clean, but experience section doesn't highlight transferable PM skills+• Summary (4/10): States transition desire but doesn't bridge sales-to-PM narrative+• Clarity (6/10): Sales role clear, but PM relevance of each bullet unclear+• Skills (3/5): Missing PM tools (Figma, analytics platforms, A/B testing)+• Grammar (5/5): Perfect+**Total: 9+16+7+11+4+6+3+5 = 61** → Adjusted to 48 (transition gap)+**Transition Feedback:** Strong foundation, but resume doesn't translate sales wins to PM language. Needs skill mapping and PM project experience.++## YOUR ANALYTICAL PROCESS (follow precisely)++### PHASE 1: RECONNAISSANCE (30 seconds)+1. **Identify Resume Type:** What industry/role? What career stage (entry/mid/senior/executive)?+2. **Set Expectations:** A new grad CANNOT have 8 quantified achievements. A nurse WON'T have GitHub links. Adjust mental baseline.+3. **First Impression:** What jumps out as strongest? What's obviously missing?++### PHASE 2: FORENSIC COUNTING (be exact)+Count these elements LITERALLY - no estimating:++**Quantified Achievements** (0-25 pts) - COUNT each number/percentage/dollar amount:+- Tip: Look for %, $, #, "increased", "reduced", "managed", "led team of"+- Format: "Found X quantified achievements: [list each one]"++**Technical Keywords** (0-20 pts) - COUNT industry-specific terms:+- Tip: Technologies, tools, methodologies, certifications, domain terms+- Format: "Found X keywords: [list them]"++**Action Verbs** (0-10 pts) - Note strong vs weak:+- Strong: Led, Architected, Transformed, Spearheaded, Delivered, Optimized+- Weak: Responsible for, Helped with, Assisted in, Worked on, Did+- Format: "Found X strong verbs, Y weak verbs"++### PHASE 3: QUALITATIVE ASSESSMENT++**Formatting Quality** (0-15 pts):+- Visual hierarchy (headings, subheadings, bullets)+- Consistent spacing and alignment+- Appropriate length (1 page for <10 yrs, 2 pages for >10 yrs)+- ATS-friendly (no tables, columns, graphics)++**Professional Summary** (0-10 pts):+- Does it answer: "What do you do? What are you great at? What value do you bring?"+- Is it customizable for target roles?+- Does it avoid clichés ("hardworking team player")?++**Experience Clarity** (0-10 pts):+- Clear company names, titles, dates+- STAR format (Situation, Task, Action, Result)+- Progression visible (increasing responsibility)++**Skills Section** (0-5 pts):+- Organized by category (languages, frameworks, tools)+- Relevant to target role+- No fluff skills ("Microsoft Word" for a developer)++**Grammar/Spelling** (0-5 pts):+- Any errors at all?+- Consistent tense (past for old roles, present for current)+- Professional tone++### PHASE 4: CALCULATE TOTAL+Show your math explicitly:+"Keywords: X + Quantified: Y + Verbs: Z + Formatting: A + Summary: B + Clarity: C + Skills: D + Grammar: E = TOTAL"++### PHASE 5: SELF-CRITIQUE CHECKLIST+Before submitting, verify:+□ Did I COUNT actual elements or just estimate?+□ Is my score within realistic range for this career stage?+□ Would a human recruiter agree with my assessment?+□ Are my suggestions SPECIFIC with examples from THIS resume?+□ Did I reference actual text from the resume in my feedback?+□ Is at least one suggestion about the HIGHEST-IMPACT improvement?++## SCORE INTERPRETATION GUIDE+- **85-100:** Exceptional - Top 5% of resumes. Ready for FAANG/top-tier companies.+- **70-84:** Above Average - Strong resume, minor polish needed. Competitive for good roles.+- **55-69:** Average - Serviceable but doesn't stand out. Needs work to compete.+- **40-54:** Below Average - Significant gaps. Major revision recommended.+- **25-39:** Weak - Fundamental issues. Needs substantial rewrite.+- **<25:** Critical - Only for nearly blank or severely problematic resumes.++## REALITY CHECK+- Most resumes score 45-65+- Entry-level resumes typically score 35-50+- Even excellent resumes rarely exceed 80+- A score of 50 is NOT bad - it's genuinely average`;++export const JOB_MATCH_SYSTEM_PROMPT = `You are an elite talent acquisition specialist and ATS systems expert who has matched 100,000+ candidates to jobs. You combine algorithmic ATS scoring with human hiring psychology to provide exceptionally accurate, strategic match assessments.++## COGNITIVE FORCING RULES (prevent common AI mistakes)++❌ DON'T: Score based on "general relevance" - match SPECIFIC requirements+✅ DO: "Job requires React 5+ years → Resume shows React 3 years = partial match (60%)"++❌ DON'T: Treat all skills as equally important+✅ DO: Weight must-haves higher than nice-to-haves++❌ DON'T: Penalize for skills the job didn't ask for+✅ DO: Only score against what's explicitly required++❌ DON'T: Give generic advice like "add more relevant skills"+✅ DO: "Add 'Kubernetes' - mentioned 3x in job requirements but missing from your resume"++❌ DON'T: Assume adjacent skills are equivalent+✅ DO: Note when skills are related but not identical (e.g., "Has GCP, job wants AWS - related but not exact")++❌ DON'T: Ignore transferable experience+✅ DO: Credit relevant experience even from different industries++## SCORE INTERPRETATION GUIDE+- **80-100:** Excellent Match - Interview likely. Apply immediately.+- **65-79:** Strong Match - Good fit. Apply with confidence.+- **50-64:** Moderate Match - Worth applying with tailored resume.+- **35-49:** Weak Match - Consider but have backup options.+- **20-34:** Poor Match - Significant gaps. Upskill first.+- **<20:** Not a Match - Wrong role/industry. Redirect search.++## REALITY CHECK+- Most candidates score 40-60 against any given job+- A score of 50 means "qualified but competitive field"+- 70+ is excellent and relatively rare+- Even strong candidates often miss 20-30% of keywords`;-IMPORTANT: The score field MUST be a number between 0-100. NEVER return 0 unless the resume is blank.+/**+ * Build user prompt for resume review with chain-of-thought instructions+ */+export function buildResumeReviewPrompt(resumeText: string): string {+ return `Analyze this resume using your expert methodology.-HOW TO CALCULATE THE SCORE (follow these steps):+## YOUR TASK-STEP 1: ATS Keywords (0-20 points)-- Look for industry-specific terms, technologies, skills-- Award: Many relevant = 20pts, Good = 15pts, Some = 10pts, Few = 5pts, None = 2pts-- Any keywords deserve at least 2-5 points+Follow the 5-phase analytical process from your training:-STEP 2: Quantified Achievements (0-25 points)-- Count achievements with numbers, percentages, metrics-- Award: 8+ = 25pts, 5-7 = 20pts, 3-4 = 15pts, 1-2 = 10pts, None = 5pts-- Any work experience deserves at least 5 points+### PHASE 1: RECONNAISSANCE+- What industry/role is this resume for?+- What career stage (entry/mid/senior/executive)?+- Adjust your baseline expectations accordingly.-STEP 3: Action Verbs (0-10 points)-- Check for strong verbs: Led, Achieved, Managed, Increased-- Award: Excellent = 10pts, Good = 7pts, Some = 5pts, Weak = 3pts+### PHASE 2: FORENSIC COUNTING (be literal)+Count these elements EXACTLY:+- Quantified achievements (%, $, numbers)+- Technical/industry keywords+- Strong vs weak action verbs-STEP 4: Formatting (0-15 points)-- Check for clean layout, consistent spacing, proper structure-- Award: Professional = 15pts, Good = 12pts, Basic = 8pts, Poor = 5pts-- Any formatted resume deserves at least 5 points+### PHASE 3: QUALITATIVE ASSESSMENT+Evaluate:+- Formatting quality (visual hierarchy, ATS-friendliness)+- Professional summary effectiveness+- Experience clarity (STAR format, progression)+- Skills section organization+- Grammar/spelling-STEP 5: Professional Summary (0-10 points)-- Check for compelling summary/objective-- Award: Excellent = 10pts, Good = 7pts, Basic = 5pts, Weak = 3pts, Missing = 1pt+### PHASE 4: CALCULATE & SHOW MATH+"Keywords: X + Quantified: Y + Verbs: Z + Formatting: A + Summary: B + Clarity: C + Skills: D + Grammar: E = TOTAL"-STEP 6: Experience Clarity (0-10 points)-- Check for clear job titles, companies, dates, descriptions-- Award: Perfect = 10pts, Good = 7pts, Basic = 5pts, Unclear = 3pts+### PHASE 5: SELF-CRITIQUE+Before finalizing:+□ Did I count actual elements (not estimate)?+□ Is my score realistic for this career stage?+□ Are my suggestions SPECIFIC to THIS resume?+□ Did I include at least one HIGH-IMPACT improvement?-STEP 7: Skills Section (0-5 points)-- Check for relevant skills listed-- Award: Comprehensive = 5pts, Good = 4pts, Basic = 3pts, Minimal = 2pts+----STEP 8: Grammar/Spelling (0-5 points)-- Check for errors-- Award: Perfect = 5pts, 1-2 errors = 4pts, 3-5 errors = 3pts, More = 2pts+## RESUME TO ANALYZE:-FINAL SCORE = Add all 8 steps together (minimum realistic score is usually 25-40)+${resumeText}-SCORE RANGES:-- 80-100: Exceptional (rare)-- 60-79: Above average-- 40-59: Average, needs work-- 20-39: Below average-- 0-19: Poor (almost never - only if mostly blank)+----Be realistic but fair. Most resumes score 45-70.`;+## OUTPUT REQUIREMENTS-export const JOB_MATCH_SYSTEM_PROMPT = `You are an expert ATS analyst. Your job is to calculate a match score between a resume and job description.+Provide your structured assessment with:+1. **score**: Your calculated total (0-100)+2. **summary**: 2-3 sentences mentioning the score, top strength, and top weakness+3. **strengths**: 3-5 specific strengths WITH evidence from the resume+4. **weaknesses**: 3-5 specific weaknesses with WHY they matter+5. **suggestions**: 3-5 actionable improvements with EXACTLY what to do-IMPORTANT: The matching_score field MUST be a number between 0-100. NEVER return 0 unless the resume is completely unrelated to the job.+Remember: Reference SPECIFIC text from this resume. No generic feedback.`;+}-HOW TO CALCULATE THE SCORE (follow these steps):+/**+ * Build user prompt for job match with chain-of-thought instructions+ */+export function buildJobMatchPrompt(+ resumeText: string,+ jobText: string+): string {+ return `Analyze this job-candidate match using your expert methodology.++## YOUR TASK++Follow the 5-phase analytical process from your training:++### PHASE 1: JOB REQUIREMENT EXTRACTION+Parse the job description completely:+- **Must-Have Skills**: What's explicitly required?+- **Nice-to-Have Skills**: What's preferred/bonus?+- **Experience Requirements**: Years, level, type+- **Qualifications**: Education, certifications+- **Keywords**: Important terms that appear multiple times++### PHASE 2: RESUME MATCHING+Create a match checklist:+| Requirement | Found? | Evidence | Match % |+For each job requirement, search the resume and note:+- Exact matches (100%)+- Related/synonym matches (60-80%)+- Adjacent skill matches (30-50%)+- Missing (0%)++### PHASE 3: SCORING (show your math)+1. **Skills Match (0-30 pts)**: X of Y skills = Z%+2. **Experience Match (0-25 pts)**: Candidate years vs required years+3. **Keyword Overlap (0-20 pts)**: X of Y keywords found+4. **Qualifications (0-15 pts)**: Education + certifications+5. **Industry Fit (0-10 pts)**: Domain relevance++### PHASE 4: STRATEGIC RECOMMENDATIONS+Provide actionable advice:+- **Quick Wins**: Keywords/skills to add to resume TODAY+- **Short-term**: Certifications, portfolio pieces (1-2 weeks)+- **Long-term**: Skills to develop (1-3 months)+- **Application Decision**: Apply now? Wait? Skip?++### PHASE 5: SELF-CRITIQUE+Before finalizing:+□ Did I extract ALL requirements from the job?+□ Did I search the resume for EACH requirement?+□ Are my suggestions SPECIFIC (exact keywords)?+□ Did I give a clear apply/don't apply recommendation?++---++## JOB DESCRIPTION:-STEP 1: Skills Match (0-30 points)-- List the key technical skills from the job description-- Count how many appear in the resume-- Award points: 100% match = 30pts, 75% = 22pts, 50% = 15pts, 25% = 8pts, 0% = 5pts-- Even basic matches deserve 5-10 points+${jobText}-STEP 2: Experience Match (0-25 points)-- Check if candidate has relevant work experience in similar roles-- Award points: Perfect = 25pts, Strong = 18pts, Moderate = 12pts, Some = 6pts, None = 3pts-- Any related experience deserves at least 3-6 points+----STEP 3: Keyword Overlap (0-20 points)-- Count important keywords from job description that appear in resume-- Award points: 80%+ = 20pts, 60% = 15pts, 40% = 10pts, 20% = 5pts, Any = 3pts-- Even basic keyword presence deserves 3-5 points+## CANDIDATE RESUME:-STEP 4: Qualifications (0-15 points)-- Check education, certifications, licenses-- Award points: Exceeds = 15pts, Meets = 12pts, Partial = 8pts, Basic = 4pts-- Any education deserves at least 4 points+${resumeText}-STEP 5: Industry/Domain (0-10 points)-- Check if candidate has industry knowledge-- Award points: Expert = 10pts, Strong = 7pts, Some = 5pts, Transferable = 3pts-- Any transferable skills deserve 3 points+----FINAL SCORE = Add all 5 steps together (minimum realistic score is usually 20-30)+## OUTPUT REQUIREMENTS-SCORE RANGES:-- 80-100: Excellent match (rare)-- 60-79: Strong candidate-- 40-59: Moderate fit, has potential-- 20-39: Weak match but possible-- 0-19: Very poor match (almost never - only if completely unrelated)+Provide your structured assessment with:+1. **matching_score**: Your calculated total (0-100)+2. **detailed_analysis**: 3-5 categories showing your scoring breakdown+ - MUST include: Skills Match, Experience Match, Keyword Overlap+ - Show specific counts and evidence+3. **suggestions**: 2-4 categories of actionable improvements+ - Include EXACT keywords to add+ - Include SPECIFIC skills to highlight+4. **additional_comments**: 2-3 sentences with:+ - Overall candidacy assessment+ - Top priority improvement+ - Clear recommendation (apply now/tailor resume/upskill first)-Be generous with base points. Most real candidates score 35-65.`;+Remember: Be SPECIFIC. Quote actual text. List exact keywords.`;+}/**- * Build user prompt for resume review.+ * Critic validation prompt - Phase 2: Second agent validates first agent's work*/-export function buildResumeReviewPrompt(resumeText: string): string {- return `Evaluate this resume by following the 8-step scoring process.--CRITICAL INSTRUCTIONS:-1. You MUST calculate points for each of the 8 steps-2. The score MUST be the sum of all 8 steps (0-100)-3. NEVER return 0 or very low scores unless the resume is blank-4. Award at least minimum points in each category if there's ANY content-5. Be specific in your feedback--RESUME:-${resumeText}--Now perform the 8-step evaluation:-- Step 1 (Keywords): Count industry terms, award 0-20 points-- Step 2 (Quantified): Count numbered achievements, award 0-25 points-- Step 3 (Action Verbs): Assess verb strength, award 0-10 points-- Step 4 (Formatting): Check layout quality, award 0-15 points-- Step 5 (Summary): Evaluate summary section, award 0-10 points-- Step 6 (Clarity): Check experience details, award 0-10 points-- Step 7 (Skills): Review skills section, award 0-5 points-- Step 8 (Grammar): Check for errors, award 0-5 points--Add up all points for the final score.`;-}+export const CRITIC_SYSTEM_PROMPT = `You are an elite quality assurance specialist for AI-generated career assessments. Your role is to catch errors, validate accuracy, and ensure actionable value.++## YOUR MISSION+Review another AI's analysis and determine if it meets quality standards. You are the last line of defense against bad advice reaching job seekers.++## VALIDATION FRAMEWORK++### 1. MATHEMATICAL ACCURACY (Critical)+□ Does the final score equal the sum of component scores?+□ Are all component scores within valid ranges?+ - Keywords: 0-20, Quantified: 0-25, Verbs: 0-10, Formatting: 0-15+ - Summary: 0-10, Clarity: 0-10, Skills: 0-5, Grammar: 0-5+□ Is the score realistic for the resume type?+ - Entry-level: typically 35-50+ - Mid-level: typically 45-65+ - Senior: typically 55-75+ - Exceptional: rarely >80+□ Flag if: Score doesn't match stated math, or extreme scores without justification++### 2. EVIDENCE QUALITY (Critical)+□ Did the analyzer QUOTE specific text from the resume?+□ Are counts actual counts, not estimates? ("Found 5 achievements" vs "several achievements")+□ Is each strength backed by a specific example?+□ Is each weakness tied to something concrete (or missing)?+□ Flag if: Generic statements like "good formatting" without specifics++### 3. ACTIONABILITY CHECK (Important)+□ Can the candidate actually DO each suggestion?+□ Are suggestions specific enough?+ - Bad: "Add more metrics"+ - Good: "Your 'Improved sales' bullet should specify the % increase"+□ Is there at least one high-impact suggestion?+□ Are suggestions prioritized or ranked?+□ Flag if: Vague, generic, or impossible-to-implement suggestions++### 4. CONSISTENCY CHECK (Important)+□ Does a high score come with strong strengths?+□ Does a low score come with significant weaknesses?+□ Do suggestions address the identified weaknesses?+□ Is the summary consistent with the detailed feedback?+□ Flag if: Score says 70 but feedback is mostly negative (or vice versa)++### 5. COMPLETENESS CHECK (Basic)+□ Are all required fields present and populated?+□ At least 2-3 strengths, weaknesses, and suggestions?+□ Is the summary 2-3 informative sentences?+□ Flag if: Empty fields, single-item lists, or one-sentence summary++### 6. COMMON AI MISTAKES TO CATCH+□ Hallucinated skills (claiming resume has X when it doesn't)+□ Missed obvious elements (ignoring stated metrics)+□ Industry-inappropriate feedback (asking nurse for GitHub)+□ Overly harsh or overly generous scoring+□ Repetitive feedback (same point stated multiple ways)+□ Generic template responses (could apply to any resume)++## YOUR RESPONSE FORMAT++**VERDICT: [APPROVED / NEEDS REVISION / REJECTED]**++**SCORE VALIDATION:**+- Stated math: [X+Y+Z = Total]+- Actual calculation: [Your verification]+- Score appropriateness: [Realistic for this resume type?]++**EVIDENCE QUALITY:**+- Specific quotes found: [Yes/No, examples]+- Counting accuracy: [Verified/Not verified]++**ACTIONABILITY:**+- Implementable suggestions: [X of Y]+- Highest-impact suggestion: [Which one?]++**ISSUES FOUND:** (if any)+1. [Issue 1 - severity: Critical/Important/Minor]+2. [Issue 2 - severity]++**RECOMMENDED CORRECTIONS:** (if NEEDS REVISION)+- [Specific fix needed]++## DECISION CRITERIA+- **APPROVED**: No critical issues, ≤2 minor issues+- **NEEDS REVISION**: 1-2 important issues OR 3+ minor issues+- **REJECTED**: Any critical issue (wrong math, hallucinated content, harmful advice)`;/**- * Build user prompt for job match analysis.+ * Build critic validation prompt*/-export function buildJobMatchPrompt(- resumeText: string,- jobText: string+export function buildCriticPrompt(+ originalAnalysis: string,+ resumeOrJobText: string): string {- return `Calculate the job match score by following the 5-step process.+ return `Validate this AI-generated analysis for quality and accuracy.-CRITICAL INSTRUCTIONS:-1. You MUST calculate points for each of the 5 steps-2. The matching_score MUST be the sum of all 5 steps (0-100)-3. NEVER return 0 or very low scores unless completely unrelated-4. Award at least minimum points in each category if there's ANY relevance-5. Be specific: list actual skills/keywords found vs missing+## ANALYSIS TO VALIDATE:+${originalAnalysis}-JOB DESCRIPTION:-${jobText}--CANDIDATE RESUME:-${resumeText}+## ORIGINAL SOURCE DOCUMENT:+${resumeOrJobText}-Now perform the 5-step evaluation:-- Step 1 (Skills): Identify key skills from job, count matches, award 0-30 points-- Step 2 (Experience): Evaluate relevant experience, award 0-25 points-- Step 3 (Keywords): Count keyword overlap, award 0-20 points-- Step 4 (Qualifications): Check education/certs, award 0-15 points-- Step 5 (Industry): Assess domain fit, award 0-10 points+## YOUR TASK:+1. Verify all math calculations+2. Check that claims are supported by the source document+3. Evaluate actionability of suggestions+4. Check for consistency between score and feedback+5. Identify any hallucinations or errors-Add up all points for the final matching_score.`;+Provide your structured verdict with specific findings.`;}diff --git a/src/lib/ai/tools.ts b/src/lib/ai/tools.tsindex e8d730a..dc0e2d6 100644--- a/src/lib/ai/tools.ts+++ b/src/lib/ai/tools.ts@@ -34,439 +34,19 @@ export function countQuantifiedAchievements(text: string): {}// ============================================================================-// DOMAIN-SPECIFIC KEYWORD SETS+// AI UNAVAILABLE ERROR - Used when semantic extraction fails// ============================================================================-const TECH_KEYWORDS = [- // Programming languages- "javascript",- "typescript",- "python",- "java",- "c#",- "c++",- "ruby",- "go",- "golang",- "rust",- "php",- "swift",- "kotlin",- "scala",- "r",- "matlab",- "perl",- "bash",- "shell",- "powershell",- // Frontend- "react",- "angular",- "vue",- "svelte",- "next.js",- "nextjs",- "nuxt",- "gatsby",- "webpack",- "vite",- "tailwind",- "css",- "sass",- "less",- "html",- "redux",- "mobx",- "zustand",- // Backend- "node",- "nodejs",- "express",- "fastify",- "nestjs",- "django",- "flask",- "fastapi",- "spring",- "spring boot",- "rails",- "ruby on rails",- ".net",- "asp.net",- "laravel",- // Cloud/DevOps- "aws",- "amazon web services",- "azure",- "gcp",- "google cloud",- "docker",- "kubernetes",- "k8s",- "ci/cd",- "jenkins",- "github actions",- "gitlab ci",- "terraform",- "ansible",- "puppet",- "chef",- "cloudformation",- "helm",- "argocd",- // Databases- "sql",- "postgresql",- "postgres",- "mysql",- "mariadb",- "mongodb",- "redis",- "dynamodb",- "cassandra",- "elasticsearch",- "neo4j",- "sqlite",- "oracle",- "mssql",- // Data/ML- "machine learning",- "deep learning",- "neural network",- "tensorflow",- "pytorch",- "keras",- "scikit-learn",- "pandas",- "numpy",- "jupyter",- "spark",- "hadoop",- "airflow",- "dbt",- "snowflake",- "databricks",- "mlops",- // API/Architecture- "api",- "rest",- "restful",- "graphql",- "grpc",- "microservices",- "serverless",- "lambda",- "event-driven",- "message queue",- "rabbitmq",- "kafka",- "sqs",- // Testing- "unit testing",- "integration testing",- "e2e",- "jest",- "mocha",- "cypress",- "playwright",- "selenium",- "pytest",- // Methodologies- "agile",- "scrum",- "kanban",- "tdd",- "bdd",- "devops",- "sre",- "gitops",-];--const HEALTHCARE_KEYWORDS = [- "hipaa",- "hl7",- "fhir",- "epic",- "cerner",- "emr",- "ehr",- "clinical",- "patient care",- "healthcare",- "medical",- "pharmacy",- "telemedicine",- "icd-10",- "cms",- "medicare",- "medicaid",- "hitech",- "meaningful use",- "clinical trials",- "fda",- "phi",- "healthcare analytics",-];--const FINANCE_KEYWORDS = [- "sox",- "sarbanes-oxley",- "kyc",- "aml",- "anti-money laundering",- "basel",- "sec",- "finra",- "pci",- "pci-dss",- "financial services",- "banking",- "trading",- "risk management",- "portfolio",- "investment",- "fintech",- "blockchain",- "cryptocurrency",- "quantitative",- "algorithmic trading",- "hedge fund",- "private equity",- "wealth management",-];--const SOFT_SKILLS = [- "leadership",- "communication",- "collaboration",- "teamwork",- "problem-solving",- "analytical",- "strategic",- "mentoring",- "coaching",- "stakeholder management",- "project management",- "cross-functional",- "presentation",- "negotiation",- "conflict resolution",- "time management",- "prioritization",- "decision making",-];--const ALL_KEYWORDS = [- ...TECH_KEYWORDS,- ...HEALTHCARE_KEYWORDS,- ...FINANCE_KEYWORDS,- ...SOFT_SKILLS,-];--/**- * Extract technical keywords and skills from text- * Uses comprehensive keyword lists across multiple domains- */-export function extractKeywords(text: string): {- keywords: string[];- count: number;-} {- const lowerText = text.toLowerCase();-- // Find matching keywords from our comprehensive lists- const foundKeywords = ALL_KEYWORDS.filter((term) =>- lowerText.includes(term.toLowerCase())- );-- // Remove duplicates (e.g., "node" and "nodejs" both match)- const uniqueKeywords = [...new Set(foundKeywords)];-- return {- keywords: uniqueKeywords,- count: uniqueKeywords.length,- };-}--/**- * Extract keywords dynamically from text (for job descriptions)- * This extracts potential skill terms that aren't in our predefined lists- */-export function extractDynamicKeywords(text: string): {- keywords: string[];- technicalTerms: string[];- tools: string[];-} {- // Extract potential technical terms using patterns- const technicalPatterns = [- // Capitalized words that might be tools/technologies (e.g., "Docker", "Kubernetes")- /\b[A-Z][a-z]+(?:\.[A-Z][a-z]+)?\b/g,- // Terms with version numbers (e.g., "Python 3.x", "React 18")- /\b[A-Za-z]+\s*\d+(?:\.\d+)*\b/g,- // Acronyms (e.g., "AWS", "GCP", "CI/CD")- /\b[A-Z]{2,5}\b/g,- ];-- const extractedTerms = new Set<string>();- technicalPatterns.forEach((pattern) => {- const matches = text.match(pattern);- if (matches) {- matches.forEach((m) => {- const term = m.trim().toLowerCase();- // Filter out common words that aren't tech terms- if (- term.length >= 2 &&- ![- "the",- "and",- "for",- "with",- "from",- "this",- "that",- "will",- "are",- ].includes(term)- ) {- extractedTerms.add(m.trim());- }- });- }- });-- // Separate into categories- const keywords: string[] = [];- const technicalTerms: string[] = [];- const tools: string[] = [];-- extractedTerms.forEach((term) => {- const lower = term.toLowerCase();- if (ALL_KEYWORDS.includes(lower)) {- keywords.push(lower);- } else if (/^[A-Z]{2,5}$/.test(term)) {- // Acronyms are likely tools/platforms- tools.push(term);- } else {- technicalTerms.push(term);- }- });-- return {- keywords: [...new Set(keywords)],- technicalTerms: [...new Set(technicalTerms)],- tools: [...new Set(tools)],- };-}--/**- * Get domain-specific keywords based on detected industry- */-export function getDomainKeywords(text: string): {- domain: string | null;- keywords: string[];-} {- const lowerText = text.toLowerCase();-- // Detect domain based on keyword frequency- const healthcareScore = HEALTHCARE_KEYWORDS.filter((k) =>- lowerText.includes(k)- ).length;- const financeScore = FINANCE_KEYWORDS.filter((k) =>- lowerText.includes(k)- ).length;-- if (healthcareScore >= 2) {- return { domain: "healthcare", keywords: HEALTHCARE_KEYWORDS };- }- if (financeScore >= 2) {- return { domain: "finance", keywords: FINANCE_KEYWORDS };+export class AIUnavailableError extends Error {+ constructor(operation: string) {+ super(`AI unavailable for ${operation}. Please try again later.`);+ this.name = "AIUnavailableError";}-- return { domain: null, keywords: TECH_KEYWORDS };}-/**- * Count strong action verbs in resume- */-export function countActionVerbs(text: string): {- count: number;- verbs: string[];-} {- const strongVerbs = [- "led",- "managed",- "created",- "developed",- "implemented",- "designed",- "built",- "launched",- "achieved",- "improved",- "increased",- "decreased",- "reduced",- "optimized",- "streamlined",- "spearheaded",- "pioneered",- "established",- "orchestrated",- "drove",- "delivered",- "executed",- "transformed",- "accelerated",- "generated",- ];-- const lowerText = text.toLowerCase();- const foundVerbs = strongVerbs.filter((verb) =>- lowerText.includes(verb.toLowerCase())- );-- return {- count: foundVerbs.length,- verbs: foundVerbs,- };-}--/**- * Calculate keyword overlap between resume and job description- */-export function calculateKeywordOverlap(- resumeText: string,- jobText: string-): {- overlapPercentage: number;- matchedKeywords: string[];- missingKeywords: string[];- totalJobKeywords: number;-} {- // Extract keywords from job description- const jobKeywords = extractKeywords(jobText);-- // Check which job keywords appear in resume- const lowerResume = resumeText.toLowerCase();- const matchedKeywords = jobKeywords.keywords.filter((keyword) =>- lowerResume.includes(keyword.toLowerCase())- );-- const missingKeywords = jobKeywords.keywords.filter(- (keyword) => !lowerResume.includes(keyword.toLowerCase())- );-- const overlapPercentage =- jobKeywords.count > 0- ? (matchedKeywords.length / jobKeywords.count) * 100- : 0;-- return {- overlapPercentage: Math.round(overlapPercentage),- matchedKeywords,- missingKeywords,- totalJobKeywords: jobKeywords.count,- };-}+// ============================================================================+// TEXT ANALYSIS UTILITIES (no hardcoded keyword lists)+// ============================================================================/*** Analyze text structure and formatting quality@@ -507,64 +87,6 @@ export function analyzeFormatting(text: string): {};}-/**- * Extract and count required skills from job description- */-export function extractRequiredSkills(jobText: string): {- requiredSkills: string[];- preferredSkills: string[];- totalSkills: number;-} {- const required: string[] = [];- const preferred: string[] = [];-- // Look for sections mentioning required/preferred- const lines = jobText.split("\n");- let inRequiredSection = false;- let inPreferredSection = false;-- lines.forEach((line) => {- const lowerLine = line.toLowerCase();-- if (- lowerLine.includes("required") ||- lowerLine.includes("must have") ||- lowerLine.includes("qualifications")- ) {- inRequiredSection = true;- inPreferredSection = false;- } else if (- lowerLine.includes("preferred") ||- lowerLine.includes("nice to have") ||- lowerLine.includes("bonus")- ) {- inPreferredSection = true;- inRequiredSection = false;- }-- // Extract skills from bullet points- if (- (line.trim().startsWith("-") ||- line.trim().startsWith("•") ||- line.trim().startsWith("*")) &&- line.length < 150- ) {- const skill = line.trim().substring(1).trim();- if (inRequiredSection && skill) {- required.push(skill);- } else if (inPreferredSection && skill) {- preferred.push(skill);- }- }- });-- return {- requiredSkills: required,- preferredSkills: preferred,- totalSkills: required.length + preferred.length,- };-}-// ============================================================================// SEMANTIC EXTRACTION FUNCTIONS (Phase 1 Improvements + Phase 4 Optimization)// Uses LLM for dynamic, context-aware extraction instead of hard-coded lists@@ -652,16 +174,7 @@ export async function extractSemanticKeywords(return object as SemanticKeywordExtraction;} catch (error) {console.error("Semantic keyword extraction failed:", error);- // Fallback to legacy extraction if LLM fails- const fallbackKeywords = extractKeywords(text);- return {- technical_skills: fallbackKeywords.keywords.slice(0, 20),- tools_platforms: [],- methodologies: [],- domain_knowledge: [],- soft_skills: [],- total_count: fallbackKeywords.count,- };+ throw new AIUnavailableError("keyword extraction");}}@@ -724,17 +237,7 @@ export async function analyzeActionVerbs(return object as ActionVerbAnalysis;} catch (error) {console.error("Action verb analysis failed:", error);- // Fallback to legacy counting if LLM fails- const fallbackVerbs = countActionVerbs(text);- return {- strong_verbs: fallbackVerbs.verbs.map((verb) => ({- verb,- context: "Found in resume",- impact_level: "medium" as const,- })),- weak_verbs: [],- verb_strength_score: Math.min(fallbackVerbs.count, 10),- };+ throw new AIUnavailableError("action verb analysis");}}@@ -833,22 +336,7 @@ export async function performSemanticSkillMatch(return cleanedResult;} catch (error) {console.error("Semantic skill matching failed:", error);- // Fallback to legacy keyword overlap if LLM fails- const fallbackOverlap = calculateKeywordOverlap(resumeText, jobText);- return {- exact_matches: fallbackOverlap.matchedKeywords.map((skill) => ({- skill,- resume_evidence: "Found in resume",- job_requirement: "Required by job",- })),- related_matches: [],- missing_skills: fallbackOverlap.missingKeywords.map((skill) => ({- skill,- importance: "important" as const,- learnability: "moderate" as const,- })),- overall_match_percentage: fallbackOverlap.overlapPercentage,- };+ throw new AIUnavailableError("skill matching");}}@@ -941,23 +429,7 @@ export async function calculateSemanticSimilarity(return object as SemanticSimilarityResult;} catch (error) {console.error("Semantic similarity calculation failed:", error);- // Fallback to legacy keyword overlap if LLM fails- const fallbackOverlap = calculateKeywordOverlap(resumeText, jobDescription);- return {- similarity_score: fallbackOverlap.overlapPercentage,- match_explanation: `Based on keyword analysis: ${fallbackOverlap.matchedKeywords.length} of ${fallbackOverlap.totalJobKeywords} keywords matched (${fallbackOverlap.overlapPercentage}% overlap).`,- key_matches: fallbackOverlap.matchedKeywords- .slice(0, 5)- .map((k) => `Has ${k}`),- key_gaps: fallbackOverlap.missingKeywords- .slice(0, 5)- .map((k) => ({ skill: k, note: "Not found in resume" })),- transferable_skills: [],- application_recommendation:- fallbackOverlap.overlapPercentage >= 60- ? "Consider applying - decent keyword match"- : "Consider upskilling before applying - low keyword match",- };+ throw new AIUnavailableError("similarity calculation");}}@@ -1098,31 +570,3 @@ export function generateMatchExplanation(};}-// ============================================================================-// LEGACY FUNCTION DEPRECATION NOTICES-// ============================================================================--/**- * @deprecated Use `extractSemanticKeywords()` instead for context-aware extraction.- * This function uses hard-coded keyword lists which may miss relevant skills- * or produce false positives.- *- * Scheduled for removal in v2.0- */-export const extractKeywordsLegacy = extractKeywords;--/**- * @deprecated Use `analyzeActionVerbs()` instead for semantic verb analysis.- * This function only counts predefined verbs and doesn't assess context.- *- * Scheduled for removal in v2.0- */-export const countActionVerbsLegacy = countActionVerbs;--/**- * @deprecated Use `calculateSemanticSimilarity()` instead for semantic matching.- * This function only performs simple string matching without understanding context.- *- * Scheduled for removal in v2.0- */-export const calculateKeywordOverlapLegacy = calculateKeywordOverlap;diff --git a/src/models/ai.model.ts b/src/models/ai.model.tsindex 0698ee0..f26328b 100644--- a/src/models/ai.model.ts+++ b/src/models/ai.model.ts@@ -21,7 +21,7 @@ export {// MULTI-AGENT TYPES// ============================================================================-export interface AgentInsightsV2 {+export interface AgentInsights {analysis: AnalysisResult;feedback: FeedbackResult;}@@ -55,9 +55,9 @@ export interface FeedbackResult {synthesisNotes: string;}-export interface CollaborativeResultV2<T> {+export interface CollaborativeResult<T> {analysis: T;- agentInsights: AgentInsightsV2;+ agentInsights: AgentInsights;baselineScore: { score: number; breakdown: Record<string, number> };warnings?: string[];}diff --git a/src/models/ai.schemas.ts b/src/models/ai.schemas.tsindex 0b5aa2d..6926301 100644--- a/src/models/ai.schemas.ts+++ b/src/models/ai.schemas.ts@@ -485,12 +485,12 @@ export const SemanticSimilaritySchema = z.object({export type SemanticSimilarityResult = z.infer<typeof SemanticSimilaritySchema>;// ============================================================================-// MULTI-AGENT V2 CONSOLIDATED SCHEMAS+// MULTI-AGENT SCHEMAS// ============================================================================/*** Analysis Agent Schema (combines Data + Keyword + Scoring)- * Used in the consolidated multi-agent V2 system for resume review and job matching+ * Used in the multi-agent system for resume review and job matching*/export const AnalysisAgentSchema = z.object({finalScore: z@@ -556,7 +556,7 @@ export type AnalysisAgentResult = z.infer<typeof AnalysisAgentSchema>;/*** Feedback Agent Schema (combines Feedback + Synthesis)- * Used in the consolidated multi-agent V2 system for actionable recommendations+ * Used in the multi-agent system for actionable recommendations*/export const FeedbackAgentSchema = z.object({strengths: z