// Extracted from a private product repo for methodology illustration. // Not runnable standalone: imports reference the private engine. Shapes, // checks, judge prompts, and flow are shown as actually used, July 2026. /* eslint-disable @typescript-eslint/no-explicit-any */ // Interview eval harness — the loop that makes interviewer-prompt changes // measurable instead of vibes. Rollouts are simulated interviews (the ported // SME simulator), scored two ways: free programmatic register checks, and an // LLM judge for the qualities regex can't see. import { readFileSync } from "node:fs"; import { drizzle } from "drizzle-orm/node-postgres"; import { Pool } from "pg"; import * as schema from "../src/db/schema"; import { autoGenerateInterview, callClaudeJson, DEFAULT_OBJECTIVES, MODEL_INTERVIEWER, } from "../src/engine"; export const EVAL_OBJECTIVE_IDS = ["core_ksao", "ai_readiness"]; const SME_NAMES = ["Maya Torres", "Devon Park", "Priya Raman", "Sam Okafor", "Lena Fischer", "Jordan Blake", "Alexis Chen", "Marcus Webb"]; export async function loadRolesFromDb() { const pool = new Pool({ connectionString: process.env.DATABASE_URL }); const db = drizzle(pool, { schema }); const roles = await db.select().from(schema.role); await pool.end(); if (!roles.length) throw new Error("No roles in DB — evals need seeded roles."); return { roles: roles.map((r) => r.seed), titles: roles.map((r) => r.title) }; } // ── Tier 1: programmatic register checks (free) ────────────────────────────── const BANNED_OPENERS = /^(that's a really|that's really|it sounds like|i appreciate|thank you for sharing|what a great)/i; export function registerChecks(transcript: string[]) { const agentTurns = transcript .filter((l) => l.startsWith("Interviewer: ")) .map((l) => l.slice("Interviewer: ".length).trim()); const per = agentTurns.map((t) => ({ words: t.split(/\s+/).length, emdash: (t.match(/—/g) || []).length, semicolons: (t.match(/;/g) || []).length, questions: (t.match(/\?/g) || []).length, bannedOpener: BANNED_OPENERS.test(t), firstWord: (t.split(/\s+/)[0] || "").toLowerCase().replace(/[^a-z']/g, ""), })); const n = per.length; let shapeRepeats = 0; for (let i = 1; i < n; i++) { const a = per[i - 1]; const b = per[i]; if (a.firstWord === b.firstWord && Math.abs(a.words - b.words) <= Math.max(4, a.words * 0.2)) shapeRepeats++; } const pct = (f: (x: any) => boolean) => (n ? per.filter(f).length / n : 0); return { turns: n, openingWords: per[0]?.words ?? 0, meanWords: n ? per.reduce((s, x) => s + x.words, 0) / n : 0, pctUnder35: pct((x) => x.words <= 35), pctNoEmdash: pct((x) => x.emdash === 0), pctNoSemicolon: pct((x) => x.semicolons === 0), pctOneQuestion: pct((x) => x.questions <= 1), pctCleanOpeners: pct((x) => !x.bannedOpener), shapeVariety: n > 1 ? 1 - shapeRepeats / (n - 1) : 1, }; } // ── Tier 2: LLM judge ───────────────────────────────────────────────────────── export async function judgeInterview(transcript: string[], roleTitle: string) { const prompt = `You are a rigorous evaluator of a spoken AI interviewer. Below is a transcript of a voice interview about the "${roleTitle}" role (the Interviewer's turns were SPOKEN ALOUD by a voice; the participant is an SME). Score the INTERVIEWER ONLY, 1-5 each, conservatively — a generous judge makes this eval worthless. TRANSCRIPT: ${transcript.join("\n")} Criteria: - spoken_register: Do the interviewer's turns sound like a real person talking (fragments, rhythm variation, listener reactions) vs written prose read aloud (balanced clauses, polished restatements, commentary about the answer)? 5 = indistinguishable from a skilled human interviewer's speech; 1 = essay sentences. - their_words: Does the interviewer pick up the participant's OWN phrases and details, or paraphrase them into abstractions? 5 = consistently their words; 1 = constant paraphrase. - probe_depth: Does it push past vague answers to concrete behavioral specifics (what happened, what did you do), including at least one altitude shift? 5 = relentless but natural; 1 = accepts vagueness. - tone_gift: Does the conversation feel like a gift to the participant (curious, warm, they're the expert) rather than an assessment of them? Any replacement-framing about AI is an automatic 2 or lower. 5 = fully a gift. - question_quality: Are the questions sharp, specific, non-repetitive, one at a time? 5 = every question earns its turn; 1 = generic or stacked. - early_payoff: Within the interviewer's FIRST THREE turns, does the participant receive one composed, role-specific observation grounded in measured data or research (concrete, source named in the sentence), connected to the shape of their work? 5 = a sharp observation early that a person in this role would find credible and worth their time; 3 = data mentioned but generic or unsourced; 1 = three turns of pure rapport or question-only openers with nothing given back. - ice_break: Does the OPENING turn break the corporate-survey expectation? The bar: a light, human, role-specific beat that shows the interviewer already knows the texture of this work (translated into how a person talks, never a number or task-list label), then one easy concrete question. 5 = you'd screenshot it because a work tool just talked like a person who gets your job; 3 = warm but generic, could open any interview; 1 = intake-form voice ("thanks for making time", "walk me through a challenging situation"). Return ONLY valid JSON: {"spoken_register":{"score":0,"why":"one sentence"},"their_words":{"score":0,"why":""},"probe_depth":{"score":0,"why":""},"tone_gift":{"score":0,"why":""},"question_quality":{"score":0,"why":""},"early_payoff":{"score":0,"why":""},"ice_break":{"score":0,"why":""},"worst_turn":{"quote":"the single weakest interviewer turn, verbatim","why":"what makes it weak"}}`; return await callClaudeJson( [{ role: "user", content: prompt }], "You are a rigorous evaluator. Return ONLY valid JSON. Score conservatively.", MODEL_INTERVIEWER, { max_tokens: 900 } ); } // ── Batch runner ───────────────────────────────────────────────────────────── export async function runBatch(opts: { n: number; registerText: string; label: string; seedData: any; titles: string[]; // Per-role system additions (e.g. the measured-map context), keyed by title. roleSuffixes?: Record; }) { const { n, registerText, label, seedData, titles, roleSuffixes = {} } = opts; const objs = DEFAULT_OBJECTIVES.filter((o) => o.always_active || EVAL_OBJECTIVE_IDS.includes(o.id)).filter( (o) => o.interview_instructions ); const jobs = Array.from({ length: n }, (_, i) => ({ role: titles[i % titles.length], sme: SME_NAMES[i % SME_NAMES.length], idx: i, })); const results: any[] = []; const POOL = 3; let cursor = 0; async function worker() { while (cursor < jobs.length) { const job = jobs[cursor++]; const t0 = Date.now(); try { const iv = await autoGenerateInterview( job.sme, "", [], () => {}, job.role, seedData, objs, "your organization", (roleSuffixes[job.role] || "") + registerText ); const checks = registerChecks(iv.transcript); const judge = await judgeInterview(iv.transcript, job.role); results.push({ ...job, transcript: iv.transcript, checks, judge, secs: Math.round((Date.now() - t0) / 1000) }); console.log(` [${label}] ${job.idx + 1}/${n} ${job.role} (${job.sme}) — ${Math.round((Date.now() - t0) / 1000)}s`); } catch (e: any) { console.error(` [${label}] ${job.idx + 1}/${n} FAILED: ${e.message}`); results.push({ ...job, error: e.message }); } } } await Promise.all(Array.from({ length: POOL }, worker)); const ok = results.filter((r) => !r.error); const meanCheck = (k: string) => (ok.length ? ok.reduce((s, r) => s + r.checks[k], 0) / ok.length : 0); const meanJudge = (k: string) => (ok.length ? ok.reduce((s, r) => s + (r.judge?.[k]?.score ?? 0), 0) / ok.length : 0); const summary = { label, n, completed: ok.length, checks: { openingWords: meanCheck("openingWords"), meanWords: meanCheck("meanWords"), pctUnder35: meanCheck("pctUnder35"), pctNoEmdash: meanCheck("pctNoEmdash"), pctNoSemicolon: meanCheck("pctNoSemicolon"), pctOneQuestion: meanCheck("pctOneQuestion"), pctCleanOpeners: meanCheck("pctCleanOpeners"), shapeVariety: meanCheck("shapeVariety"), }, judge: { spoken_register: meanJudge("spoken_register"), their_words: meanJudge("their_words"), probe_depth: meanJudge("probe_depth"), tone_gift: meanJudge("tone_gift"), question_quality: meanJudge("question_quality"), early_payoff: meanJudge("early_payoff"), ice_break: meanJudge("ice_break"), }, }; return { summary, results }; } export function printSummary(s: any) { const pc = (x: number) => `${Math.round(x * 100)}%`; const j = (x: number) => x.toFixed(2); console.log(`\n═ ${s.label} — ${s.completed}/${s.n} interviews ═`); console.log(` Register (programmatic): opening ${Math.round(s.checks.openingWords)}w · mean ${Math.round(s.checks.meanWords)}w · ≤35w ${pc(s.checks.pctUnder35)} · no-emdash ${pc(s.checks.pctNoEmdash)} · ≤1? ${pc(s.checks.pctOneQuestion)} · clean-openers ${pc(s.checks.pctCleanOpeners)} · shape-variety ${pc(s.checks.shapeVariety)}`); console.log(` Judge (1-5): spoken ${j(s.judge.spoken_register)} · their-words ${j(s.judge.their_words)} · probe ${j(s.judge.probe_depth)} · gift ${j(s.judge.tone_gift)} · questions ${j(s.judge.question_quality)} · early-payoff ${j(s.judge.early_payoff)} · ice-break ${j(s.judge.ice_break)}`); } export function loadRegister(path?: string) { if (!path) return null; return readFileSync(path, "utf8"); }