@tangle-network/agent-eval 0.120.1 → 0.120.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/dist/analyst/index.d.ts +0 -3111
- package/dist/analyst/index.js +0 -403
- package/dist/analyst/index.js.map +0 -1
- package/dist/authenticity/index.d.ts +0 -161
- package/dist/authenticity/index.js +0 -215
- package/dist/authenticity/index.js.map +0 -1
- package/dist/belief-state/index.d.ts +0 -1301
- package/dist/belief-state/index.js +0 -2152
- package/dist/belief-state/index.js.map +0 -1
- package/dist/benchmarks/index.d.ts +0 -974
- package/dist/benchmarks/index.js +0 -60
- package/dist/benchmarks/index.js.map +0 -1
- package/dist/builder-eval/index.d.ts +0 -695
- package/dist/builder-eval/index.js +0 -366
- package/dist/builder-eval/index.js.map +0 -1
- package/dist/campaign/index.d.ts +0 -7454
- package/dist/campaign/index.js +0 -272
- package/dist/campaign/index.js.map +0 -1
- package/dist/chunk-32BZXMSO.js +0 -3878
- package/dist/chunk-32BZXMSO.js.map +0 -1
- package/dist/chunk-3A246TSA.js +0 -998
- package/dist/chunk-3A246TSA.js.map +0 -1
- package/dist/chunk-3RF76KTD.js +0 -84
- package/dist/chunk-3RF76KTD.js.map +0 -1
- package/dist/chunk-3YYRZDON.js +0 -45
- package/dist/chunk-3YYRZDON.js.map +0 -1
- package/dist/chunk-4I2E3LLO.js +0 -1030
- package/dist/chunk-4I2E3LLO.js.map +0 -1
- package/dist/chunk-ARU2PZFM.js +0 -312
- package/dist/chunk-ARU2PZFM.js.map +0 -1
- package/dist/chunk-BOD4O7OF.js +0 -40
- package/dist/chunk-BOD4O7OF.js.map +0 -1
- package/dist/chunk-DPZAEKA6.js +0 -880
- package/dist/chunk-DPZAEKA6.js.map +0 -1
- package/dist/chunk-DTJ6QUQB.js +0 -131
- package/dist/chunk-DTJ6QUQB.js.map +0 -1
- package/dist/chunk-GGE4NNQT.js +0 -65
- package/dist/chunk-GGE4NNQT.js.map +0 -1
- package/dist/chunk-H5UD2323.js +0 -286
- package/dist/chunk-H5UD2323.js.map +0 -1
- package/dist/chunk-HHWE3POT.js +0 -94
- package/dist/chunk-HHWE3POT.js.map +0 -1
- package/dist/chunk-HKUCJ437.js +0 -787
- package/dist/chunk-HKUCJ437.js.map +0 -1
- package/dist/chunk-JHCHEVET.js +0 -274
- package/dist/chunk-JHCHEVET.js.map +0 -1
- package/dist/chunk-JHOJHHU7.js +0 -867
- package/dist/chunk-JHOJHHU7.js.map +0 -1
- package/dist/chunk-JM2SKQMS.js +0 -750
- package/dist/chunk-JM2SKQMS.js.map +0 -1
- package/dist/chunk-JN2FCO5W.js +0 -7958
- package/dist/chunk-JN2FCO5W.js.map +0 -1
- package/dist/chunk-K4DBDHLK.js +0 -158
- package/dist/chunk-K4DBDHLK.js.map +0 -1
- package/dist/chunk-K6N6XJJX.js +0 -306
- package/dist/chunk-K6N6XJJX.js.map +0 -1
- package/dist/chunk-MA6HLL3S.js +0 -65
- package/dist/chunk-MA6HLL3S.js.map +0 -1
- package/dist/chunk-MAZ26DC7.js +0 -99
- package/dist/chunk-MAZ26DC7.js.map +0 -1
- package/dist/chunk-MOXWMGPC.js +0 -577
- package/dist/chunk-MOXWMGPC.js.map +0 -1
- package/dist/chunk-NJC7U437.js +0 -626
- package/dist/chunk-NJC7U437.js.map +0 -1
- package/dist/chunk-NPCTHQIO.js +0 -91
- package/dist/chunk-NPCTHQIO.js.map +0 -1
- package/dist/chunk-ONWEPEDO.js +0 -57
- package/dist/chunk-ONWEPEDO.js.map +0 -1
- package/dist/chunk-OYZAPX5G.js +0 -1526
- package/dist/chunk-OYZAPX5G.js.map +0 -1
- package/dist/chunk-PC4UYEBM.js +0 -166
- package/dist/chunk-PC4UYEBM.js.map +0 -1
- package/dist/chunk-PICTDURQ.js +0 -766
- package/dist/chunk-PICTDURQ.js.map +0 -1
- package/dist/chunk-PJQFMIOX.js +0 -1182
- package/dist/chunk-PJQFMIOX.js.map +0 -1
- package/dist/chunk-PXD6ZFNY.js +0 -1107
- package/dist/chunk-PXD6ZFNY.js.map +0 -1
- package/dist/chunk-PXE2VKMX.js +0 -140
- package/dist/chunk-PXE2VKMX.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -10
- package/dist/chunk-PZ5AY32C.js.map +0 -1
- package/dist/chunk-QBRSJK47.js +0 -622
- package/dist/chunk-QBRSJK47.js.map +0 -1
- package/dist/chunk-QWMPPZ3X.js +0 -550
- package/dist/chunk-QWMPPZ3X.js.map +0 -1
- package/dist/chunk-S3UZOQ5Y.js +0 -328
- package/dist/chunk-S3UZOQ5Y.js.map +0 -1
- package/dist/chunk-S5TT5R3L.js +0 -2668
- package/dist/chunk-S5TT5R3L.js.map +0 -1
- package/dist/chunk-T4SQEITX.js +0 -95
- package/dist/chunk-T4SQEITX.js.map +0 -1
- package/dist/chunk-TT4KNT67.js +0 -124
- package/dist/chunk-TT4KNT67.js.map +0 -1
- package/dist/chunk-U5CHZ5M3.js +0 -357
- package/dist/chunk-U5CHZ5M3.js.map +0 -1
- package/dist/chunk-ULOKLHIQ.js +0 -1937
- package/dist/chunk-ULOKLHIQ.js.map +0 -1
- package/dist/chunk-VI2UW6B6.js +0 -162
- package/dist/chunk-VI2UW6B6.js.map +0 -1
- package/dist/chunk-VQMK5FMP.js +0 -247
- package/dist/chunk-VQMK5FMP.js.map +0 -1
- package/dist/chunk-VSMTAMNK.js +0 -53
- package/dist/chunk-VSMTAMNK.js.map +0 -1
- package/dist/chunk-VZSRQ272.js +0 -149
- package/dist/chunk-VZSRQ272.js.map +0 -1
- package/dist/chunk-WW2A73HW.js +0 -159
- package/dist/chunk-WW2A73HW.js.map +0 -1
- package/dist/chunk-X4UCIOTZ.js +0 -136
- package/dist/chunk-X4UCIOTZ.js.map +0 -1
- package/dist/chunk-XDIRG3TO.js +0 -1266
- package/dist/chunk-XDIRG3TO.js.map +0 -1
- package/dist/chunk-XJYR7XFV.js +0 -317
- package/dist/chunk-XJYR7XFV.js.map +0 -1
- package/dist/chunk-ZET2UAYW.js +0 -89
- package/dist/chunk-ZET2UAYW.js.map +0 -1
- package/dist/chunk-ZZUXHH3R.js +0 -99
- package/dist/chunk-ZZUXHH3R.js.map +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -112
- package/dist/cli.js.map +0 -1
- package/dist/contract/index.d.ts +0 -4972
- package/dist/contract/index.js +0 -1654
- package/dist/contract/index.js.map +0 -1
- package/dist/control.d.ts +0 -1013
- package/dist/control.js +0 -34
- package/dist/control.js.map +0 -1
- package/dist/fuzz.d.ts +0 -759
- package/dist/fuzz.js +0 -714
- package/dist/fuzz.js.map +0 -1
- package/dist/hosted/index.d.ts +0 -730
- package/dist/hosted/index.js +0 -14
- package/dist/hosted/index.js.map +0 -1
- package/dist/index.d.ts +0 -16780
- package/dist/index.js +0 -12168
- package/dist/index.js.map +0 -1
- package/dist/matrix/index.d.ts +0 -155
- package/dist/matrix/index.js +0 -8
- package/dist/matrix/index.js.map +0 -1
- package/dist/meta-eval/index.d.ts +0 -1030
- package/dist/meta-eval/index.js +0 -417
- package/dist/meta-eval/index.js.map +0 -1
- package/dist/multishot/index.d.ts +0 -579
- package/dist/multishot/index.js +0 -589
- package/dist/multishot/index.js.map +0 -1
- package/dist/openapi.json +0 -992
- package/dist/pipelines/index.d.ts +0 -567
- package/dist/pipelines/index.js +0 -515
- package/dist/pipelines/index.js.map +0 -1
- package/dist/reporting.d.ts +0 -1277
- package/dist/reporting.js +0 -48
- package/dist/reporting.js.map +0 -1
- package/dist/rl.d.ts +0 -4092
- package/dist/rl.js +0 -1724
- package/dist/rl.js.map +0 -1
- package/dist/run-campaign-HNFPJET4.js +0 -14
- package/dist/run-campaign-HNFPJET4.js.map +0 -1
- package/dist/storyboard/index.d.ts +0 -279
- package/dist/storyboard/index.js +0 -767
- package/dist/storyboard/index.js.map +0 -1
- package/dist/trace-attributes.d.ts +0 -52
- package/dist/trace-attributes.js +0 -62
- package/dist/trace-attributes.js.map +0 -1
- package/dist/traces.d.ts +0 -2343
- package/dist/traces.js +0 -249
- package/dist/traces.js.map +0 -1
- package/dist/wire/index.d.ts +0 -1252
- package/dist/wire/index.js +0 -81
- package/dist/wire/index.js.map +0 -1
package/dist/rl.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rl/adaptation-eval.ts","../src/rl/compute-curves.ts","../src/rl/contamination.ts","../src/rl/corpus.ts","../src/rl/exporters.ts","../src/rl/dataset.ts","../src/rl/predictive-validity-researcher.ts","../src/rl/preferences.ts","../src/rl/process-reward.ts","../src/rl/rl-campaign.ts","../src/rl/run-record-adapters.ts","../src/rl/sim-fidelity.ts","../src/rl/tournament.ts"],"sourcesContent":["/**\n * Sample-efficient adaptation evaluation.\n *\n * For foundation-model-based agents, the load-bearing capability isn't\n * raw end-state performance — it's *how fast the agent reaches that\n * performance from cold start*. The same model with a worse prompt that\n * adapts in 5 demonstrations beats the same model with a better prompt\n * that needs 50. Standard meta-learning eval (Finn et al., MAML, RL² lit)\n * reports an *adaptation curve*: score after k=0, 1, 2, 4, 8, 16, …\n * in-context examples or fine-tune steps.\n *\n * This module ships:\n *\n * 1. `runAdaptationCurve` — given a runner that takes k demonstrations\n * and returns a score, produce the (k, score) curve.\n * 2. `compareAdaptationCurves` — paired comparison across two policies.\n * Returns per-k delta with bootstrap CIs and an \"area-under-curve\"\n * summary statistic.\n * 3. `firstPassK` — for pass/fail evaluation, the minimum k at which\n * the policy reliably passes (≥ pass-rate threshold over reps).\n *\n * Use cases:\n * - Compare two prompt designs that have similar end-state performance\n * but different in-context efficiency.\n * - Decide between fine-tuning and prompting based on adaptation cost.\n * - Detect when a policy \"memorizes\" k=0 inputs vs. genuinely adapts.\n */\n\nexport interface AdaptationRunner<S> {\n /**\n * Runs the policy on `scenario` with `k` demonstrations. Returns a\n * scalar score in [0, 1]. The runner is responsible for any caching;\n * the harness calls it once per (scenario, k, rep) cell.\n */\n run(args: { scenario: S; k: number; rep: number }): Promise<number>\n}\n\nexport interface RunAdaptationCurveOptions<S> {\n scenarios: S[]\n /** Number-of-shots to evaluate at. Default `[0, 1, 2, 4, 8, 16]`. */\n ks?: number[]\n /** Reps per (scenario, k) cell. Default 3. */\n reps?: number\n runner: AdaptationRunner<S>\n /** Pass-rate threshold for `firstPassK` reporting. Default 0.5. */\n passThreshold?: number\n}\n\nexport interface AdaptationPoint {\n k: number\n meanScore: number\n passRate: number\n std: number\n n: number\n /** Per-scenario means at this k. */\n perScenario: Array<{ scenarioId: string; meanScore: number; passes: number; total: number }>\n}\n\nexport interface AdaptationCurve {\n points: AdaptationPoint[]\n /**\n * Smallest `k` at which `passRate ≥ passThreshold`. `null` if no `k`\n * tested reaches it.\n */\n firstPassK: number | null\n /**\n * Area under the (k, meanScore) curve, normalized by max-k. A\n * single-number summary of \"how well does this policy adapt from\n * cold-start to fully-conditioned.\" Higher = better adapter.\n */\n adaptationArea: number\n}\n\nexport async function runAdaptationCurve<S extends { scenarioId?: string }>(\n opts: RunAdaptationCurveOptions<S>,\n): Promise<AdaptationCurve> {\n const ks = opts.ks ?? [0, 1, 2, 4, 8, 16]\n const reps = opts.reps ?? 3\n const passThreshold = opts.passThreshold ?? 0.5\n const sortedKs = [...ks].sort((a, b) => a - b)\n\n const points: AdaptationPoint[] = []\n for (const k of sortedKs) {\n const perScenario: AdaptationPoint['perScenario'] = []\n const allScores: number[] = []\n let totalPasses = 0\n let totalAttempts = 0\n for (const scenario of opts.scenarios) {\n const sid = scenario.scenarioId ?? `scenario-${opts.scenarios.indexOf(scenario)}`\n const scores: number[] = []\n let passes = 0\n for (let r = 0; r < reps; r++) {\n const score = await opts.runner.run({ scenario, k, rep: r })\n scores.push(score)\n if (score >= passThreshold) passes++\n allScores.push(score)\n if (score >= passThreshold) totalPasses++\n totalAttempts++\n }\n const meanS = scores.reduce((s, v) => s + v, 0) / scores.length\n perScenario.push({ scenarioId: sid, meanScore: meanS, passes, total: scores.length })\n }\n const meanScore = allScores.reduce((s, v) => s + v, 0) / Math.max(1, allScores.length)\n const variance =\n allScores.length < 2\n ? 0\n : allScores.reduce((s, v) => s + (v - meanScore) ** 2, 0) / (allScores.length - 1)\n points.push({\n k,\n meanScore,\n passRate: totalPasses / Math.max(1, totalAttempts),\n std: Math.sqrt(variance),\n n: allScores.length,\n perScenario,\n })\n }\n\n const firstPassK = points.find((p) => p.passRate >= passThreshold)?.k ?? null\n const maxK = sortedKs[sortedKs.length - 1] ?? 1\n // Trapezoidal area under the (k, meanScore) curve, normalized by k-range.\n let area = 0\n for (let i = 1; i < points.length; i++) {\n const x1 = points[i - 1]!.k\n const x2 = points[i]!.k\n const y1 = points[i - 1]!.meanScore\n const y2 = points[i]!.meanScore\n area += ((y1 + y2) / 2) * (x2 - x1)\n }\n const adaptationArea = maxK === 0 ? 0 : area / maxK\n\n return { points, firstPassK, adaptationArea }\n}\n\nexport interface CompareCurvesResult {\n perK: Array<{\n k: number\n deltaMean: number\n aLow: number\n aHigh: number\n bLow: number\n bHigh: number\n }>\n areaDelta: number\n firstPassKDelta: number | null\n /** Verdict: 'a_better' | 'b_better' | 'similar'. */\n verdict: 'a_better' | 'b_better' | 'similar'\n /** Rationale, ready to render. */\n rationale: string\n}\n\n/**\n * Paired comparison of two adaptation curves. Per-k deltas with 95%\n * bootstrap CIs (constructed from each curve's `perScenario` per-k means\n * — the bootstrap unit is the scenario, not the rep).\n */\nexport function compareAdaptationCurves(\n a: AdaptationCurve,\n b: AdaptationCurve,\n opts: { confidence?: number; bootstrapResamples?: number; seed?: number } = {},\n): CompareCurvesResult {\n const conf = opts.confidence ?? 0.95\n const resamples = opts.bootstrapResamples ?? 500\n const rng = makeRng(opts.seed)\n\n const perK: CompareCurvesResult['perK'] = []\n for (const ap of a.points) {\n const bp = b.points.find((p) => p.k === ap.k)\n if (!bp) continue\n const aMeans = ap.perScenario.map((s) => s.meanScore)\n const bMeans = bp.perScenario.map((s) => s.meanScore)\n const aCi = bootstrapMeanCi(aMeans, resamples, conf, rng)\n const bCi = bootstrapMeanCi(bMeans, resamples, conf, rng)\n perK.push({\n k: ap.k,\n deltaMean: ap.meanScore - bp.meanScore,\n aLow: aCi.low,\n aHigh: aCi.high,\n bLow: bCi.low,\n bHigh: bCi.high,\n })\n }\n\n const areaDelta = a.adaptationArea - b.adaptationArea\n const firstPassKDelta =\n a.firstPassK !== null && b.firstPassK !== null\n ? b.firstPassK - a.firstPassK // smaller k for a means a adapts faster (positive delta)\n : null\n\n // Composite verdict: positive area delta + most per-k deltas in same\n // direction → that side wins. Within ε of zero on both → similar.\n const meanDelta = perK.reduce((s, p) => s + p.deltaMean, 0) / Math.max(1, perK.length)\n let verdict: CompareCurvesResult['verdict']\n if (Math.abs(meanDelta) < 0.02 && Math.abs(areaDelta) < 0.02) verdict = 'similar'\n else if (meanDelta > 0 && areaDelta > 0) verdict = 'a_better'\n else if (meanDelta < 0 && areaDelta < 0) verdict = 'b_better'\n else verdict = 'similar'\n\n const rationale =\n `mean per-k delta=${meanDelta.toFixed(3)}, area delta=${areaDelta.toFixed(3)}` +\n (firstPassKDelta !== null ? `, first-pass-k delta=${firstPassKDelta}` : '')\n\n return { perK, areaDelta, firstPassKDelta, verdict, rationale }\n}\n\n/** First k at which the curve's per-scenario pass rate reliably hits the threshold. */\nexport function firstPassK(curve: AdaptationCurve, threshold = 0.5): number | null {\n return curve.points.find((p) => p.passRate >= threshold)?.k ?? null\n}\n\n// ── Helpers ──────────────────────────────────────────────────────────────\n\nfunction makeRng(seed?: number): () => number {\n if (seed === undefined) return Math.random\n let s = seed >>> 0\n return () => {\n s = (s + 0x6d2b79f5) >>> 0\n let t = s\n t = Math.imul(t ^ (t >>> 15), t | 1)\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61)\n return ((t ^ (t >>> 14)) >>> 0) / 4294967296\n }\n}\n\nfunction bootstrapMeanCi(\n xs: number[],\n resamples: number,\n confidence: number,\n rng: () => number,\n): { low: number; high: number } {\n if (xs.length < 2) return { low: xs[0] ?? 0, high: xs[0] ?? 0 }\n const samples = new Array<number>(resamples)\n for (let b = 0; b < resamples; b++) {\n let sum = 0\n for (let i = 0; i < xs.length; i++) sum += xs[Math.floor(rng() * xs.length)]!\n samples[b] = sum / xs.length\n }\n samples.sort((a, b) => a - b)\n const alpha = 1 - confidence\n return {\n low: samples[Math.floor((alpha / 2) * resamples)]!,\n high: samples[Math.min(resamples - 1, Math.ceil((1 - alpha / 2) * resamples) - 1)]!,\n }\n}\n","/**\n * Test-time compute scaling curves.\n *\n * The test-time-compute frontier paper (Snell et al. 2024) and the\n * subsequent o1-style scaling work both show that LLM-agent capability\n * is a function of the compute budget at inference, not just of the\n * training run. The right way to characterize a candidate is therefore\n * a *curve* — score at compute budgets {1×, 4×, 16×, …} — not a single\n * point.\n *\n * This module ships:\n *\n * 1. The compute-curve harness — `runComputeCurve(runner, budgets)` —\n * that evaluates one candidate at a sequence of compute budgets\n * and returns the (compute, score) curve.\n * 2. A best-of-N evaluator — `bestOfN(runner, n, scoreFn)` — the\n * simplest test-time-compute scaling primitive: sample N\n * independent rollouts, return the best.\n * 3. A self-consistency evaluator — `selfConsistency(runner, n)` —\n * the majority-vote variant of best-of-N for tasks with a small\n * categorical answer space.\n * 4. Pareto-frontier extraction over multiple candidates — given\n * (candidate, compute, score) tuples, return the set of\n * candidate-compute combinations that aren't dominated.\n *\n * Caveat: \"compute\" here is the caller's notion of a compute unit. For\n * agent eval that's typically wall-time × parallelism, or token budget,\n * or LLM-call count. We accept whatever the caller provides; the curve\n * is on whatever axis they pick.\n */\n\nimport { ValidationError } from '../errors'\n\nexport interface ComputeCurveBudget {\n /** Identifier — for the report. Common: '1x', '4x', '16x'. */\n id: string\n /** Numeric value on the chosen axis (tokens, calls, USD, ms — caller picks). */\n cost: number\n /** Free-form metadata (the caller can carry per-budget config). */\n meta?: Record<string, unknown>\n}\n\nexport interface ComputeCurvePoint {\n budgetId: string\n cost: number\n score: number\n /** Number of underlying samples used at this budget. */\n samples: number\n /** Optional spread / variance information. */\n std?: number\n /** Any extra metrics the runner returned. */\n metrics?: Record<string, number>\n}\n\nexport interface ComputeCurve {\n candidateId: string\n points: ComputeCurvePoint[]\n /** Rough exponent fit: score ≈ a + b * log(cost). Useful for \"how steep is the curve?\" */\n logSlope: number | null\n /** Best (highest-score) point on the curve. */\n best: ComputeCurvePoint\n}\n\nexport interface RunComputeCurveOptions {\n candidateId: string\n budgets: ComputeCurveBudget[]\n /**\n * Run the candidate at one budget. Returns the realized score plus\n * optional spread + extra metrics.\n */\n runAtBudget: (budget: ComputeCurveBudget) => Promise<{\n score: number\n samples: number\n std?: number\n metrics?: Record<string, number>\n }>\n}\n\nexport async function runComputeCurve(opts: RunComputeCurveOptions): Promise<ComputeCurve> {\n const points: ComputeCurvePoint[] = []\n for (const budget of opts.budgets) {\n const r = await opts.runAtBudget(budget)\n points.push({\n budgetId: budget.id,\n cost: budget.cost,\n score: r.score,\n samples: r.samples,\n std: r.std,\n metrics: r.metrics,\n })\n }\n const sorted = [...points].sort((a, b) => a.cost - b.cost)\n const logSlope = sorted.length >= 2 ? fitLogSlope(sorted) : null\n const best = points.reduce((a, b) => (b.score > a.score ? b : a))\n return { candidateId: opts.candidateId, points: sorted, logSlope, best }\n}\n\nexport interface ComputeBestOfNOptions<O> {\n /** Number of independent samples to draw. */\n n: number\n /** Sampler — produces one rollout. */\n sample: (sampleIdx: number) => Promise<O>\n /** Score one rollout. */\n scoreFn: (rollout: O) => Promise<number> | number\n}\n\nexport interface ComputeBestOfNResult<O> {\n best: O\n bestScore: number\n scores: number[]\n meanScore: number\n /** Index of the best rollout, for diagnostics. */\n bestIndex: number\n}\n\n/** The simplest test-time scaling primitive. */\nexport async function bestOfN<O>(opts: ComputeBestOfNOptions<O>): Promise<ComputeBestOfNResult<O>> {\n if (opts.n <= 0) throw new ValidationError('bestOfN: n must be > 0')\n const rollouts: O[] = []\n const scores: number[] = []\n for (let i = 0; i < opts.n; i++) {\n const r = await opts.sample(i)\n rollouts.push(r)\n scores.push(await opts.scoreFn(r))\n }\n let bestIndex = 0\n for (let i = 1; i < scores.length; i++) if (scores[i]! > scores[bestIndex]!) bestIndex = i\n const meanScore = scores.reduce((s, x) => s + x, 0) / scores.length\n return {\n best: rollouts[bestIndex]!,\n bestScore: scores[bestIndex]!,\n scores,\n meanScore,\n bestIndex,\n }\n}\n\nexport interface SelfConsistencyOptions<O> {\n n: number\n sample: (sampleIdx: number) => Promise<O>\n /** Extract the canonical answer key (string) from a rollout. */\n answerKey: (rollout: O) => string\n}\n\nexport interface SelfConsistencyResult<O> {\n /** Modal answer (the majority vote). */\n answer: string\n /** Fraction of samples voting for the modal answer in [0, 1]. */\n agreement: number\n /** Histogram of all answers. */\n histogram: Record<string, number>\n /** A representative rollout that voted for the modal answer. */\n representative: O\n /** All rollouts. */\n rollouts: O[]\n}\n\n/**\n * Self-consistency / majority-vote test-time scaling. For tasks with a\n * small categorical answer space (math problems, multiple choice).\n */\nexport async function selfConsistency<O>(\n opts: SelfConsistencyOptions<O>,\n): Promise<SelfConsistencyResult<O>> {\n if (opts.n <= 0) throw new ValidationError('selfConsistency: n must be > 0')\n const rollouts: O[] = []\n const histogram: Record<string, number> = {}\n for (let i = 0; i < opts.n; i++) {\n const r = await opts.sample(i)\n rollouts.push(r)\n const key = opts.answerKey(r)\n histogram[key] = (histogram[key] ?? 0) + 1\n }\n let answer = ''\n let max = -1\n for (const [k, v] of Object.entries(histogram)) {\n if (v > max) {\n max = v\n answer = k\n }\n }\n const representative = rollouts.find((r) => opts.answerKey(r) === answer) ?? rollouts[0]!\n return {\n answer,\n agreement: max / opts.n,\n histogram,\n representative,\n rollouts,\n }\n}\n\n/**\n * Pareto frontier over (candidate, compute, score) tuples. A point is on\n * the frontier iff no other point dominates it in both score (higher\n * better) and cost (lower better). Returns the frontier sorted ascending\n * by cost.\n */\nexport interface ParetoPointInput {\n candidateId: string\n budgetId: string\n cost: number\n score: number\n}\n\nexport function paretoFrontier(points: ParetoPointInput[]): ParetoPointInput[] {\n const onFrontier: ParetoPointInput[] = []\n for (const p of points) {\n const dominated = points.some(\n (q) =>\n q !== p && q.cost <= p.cost && q.score >= p.score && (q.cost < p.cost || q.score > p.score),\n )\n if (!dominated) onFrontier.push(p)\n }\n return onFrontier.sort((a, b) => a.cost - b.cost)\n}\n\n// ── Helpers ──────────────────────────────────────────────────────────────\n\nfunction fitLogSlope(points: ComputeCurvePoint[]): number {\n // OLS slope of score on log(cost). Used as a single-number summary of\n // how much marginal compute helps. Positive = score improves with\n // compute; near-zero = capability ceiling reached.\n const xs = points.map((p) => Math.log(Math.max(1e-12, p.cost)))\n const ys = points.map((p) => p.score)\n const n = xs.length\n const mx = xs.reduce((s, x) => s + x, 0) / n\n const my = ys.reduce((s, y) => s + y, 0) / n\n let num = 0\n let den = 0\n for (let i = 0; i < n; i++) {\n num += (xs[i]! - mx) * (ys[i]! - my)\n den += (xs[i]! - mx) ** 2\n }\n return den === 0 ? 0 : num / den\n}\n","/**\n * Contamination probe — held-out perturbation tests.\n *\n * The bug class: once a benchmark scenario set is published, models train\n * on it, and your scores become invalid. SWE-Bench-Verified, GPQA, and\n * MMLU-Pro all exist because their predecessors got contaminated within\n * months. The right defense is to keep a held-out *perturbed* version of\n * every scenario — same task, slightly different surface — and check\n * whether scores diverge significantly. Genuine capability transfers; rote\n * memorization doesn't.\n *\n * This module ships the probe contract:\n *\n * 1. A `ScenarioPerturbation` strategy type — function that produces a\n * perturbed scenario from an original.\n * 2. `runContaminationProbe({ originals, perturbed, scoreFn })` — runs\n * both halves and reports per-scenario score divergence + a global\n * contamination verdict via paired Wilcoxon.\n * 3. Several stock perturbations: `renameVariables`, `shuffleOrder`,\n * `paraphrasePrompt`, `injectIrrelevantClause`. Each preserves the\n * task's structural difficulty while breaking surface memorization.\n *\n * The verdict is conservative: if the perturbed-vs-original score\n * difference is statistically significant (BH-adjusted p < 0.05) AND\n * the median drop is > 5 percentage points, we flag *contamination\n * suspected*. False positives are possible (the perturbation might\n * actually be harder); the default is to flag for review, not to\n * autoreject.\n */\n\nimport { ValidationError } from '../errors'\nimport { benjaminiHochberg, wilcoxonSignedRank } from '../statistics'\n\nexport type ScenarioPerturbationKind =\n | 'rename_variables'\n | 'shuffle_order'\n | 'paraphrase'\n | 'inject_irrelevant_clause'\n | 'custom'\n\nexport interface ScenarioPerturbation<S> {\n kind: ScenarioPerturbationKind\n /** Apply to one scenario, return its perturbed sibling. */\n apply: (scenario: S) => Promise<S> | S\n /** Optional id — for the report. */\n id?: string\n}\n\nexport interface ContaminationProbeInput<S> {\n /** Identity of every scenario. The probe's `runFingerprint` keys on these. */\n scenarioId: (s: S) => string\n /** Original scenarios. */\n originals: S[]\n /**\n * Either pre-computed perturbations (one per original, same order) OR a\n * `perturbation` strategy that synthesizes them on the fly.\n */\n perturbed?: S[]\n perturbation?: ScenarioPerturbation<S>\n /**\n * Run the policy/agent against one scenario and return a scalar score\n * in [0, 1]. The probe doesn't care what the policy is — that's the\n * caller's contract.\n */\n scoreFn: (s: S) => Promise<number>\n}\n\nexport interface ContaminationProbeOptions {\n /** Drop scores below this from the probe; treats partial failures separately. Default 0. */\n scoreFloor?: number\n /**\n * BH-FDR threshold for declaring contamination on each per-scenario\n * delta. Default 0.05.\n */\n fdr?: number\n /**\n * Minimum median per-scenario drop to flag global contamination. Default\n * 0.05 (5 percentage points). Smaller drops may be noise.\n */\n minMedianDrop?: number\n}\n\nexport interface ContaminationProbeReport {\n perScenario: Array<{\n scenarioId: string\n originalScore: number\n perturbedScore: number\n delta: number // perturbed - original (negative = drop)\n /** Per-scenario q-value (single-test BH for a single scenario). Mainly for display. */\n qValue: number\n }>\n /** Wilcoxon paired-test on the deltas. */\n pairedTest: { w: number; p: number }\n medianDelta: number\n meanDelta: number\n contaminationSuspected: boolean\n reason: string\n /** Number of scenarios processed. */\n n: number\n}\n\nexport async function runContaminationProbe<S>(\n input: ContaminationProbeInput<S>,\n opts: ContaminationProbeOptions = {},\n): Promise<ContaminationProbeReport> {\n const fdr = opts.fdr ?? 0.05\n const minMedianDrop = opts.minMedianDrop ?? 0.05\n const floor = opts.scoreFloor ?? 0\n\n if (!input.perturbed && !input.perturbation) {\n throw new ValidationError(\n 'runContaminationProbe: must supply either `perturbed` or `perturbation`.',\n )\n }\n const perturbed: S[] =\n input.perturbed ?? (await Promise.all(input.originals.map((s) => input.perturbation!.apply(s))))\n if (perturbed.length !== input.originals.length) {\n throw new ValidationError(\n `runContaminationProbe: perturbed length ${perturbed.length} ≠ originals ${input.originals.length}`,\n )\n }\n\n // Score both halves.\n const origScores = await Promise.all(input.originals.map((s) => input.scoreFn(s)))\n const pertScores = await Promise.all(perturbed.map((s) => input.scoreFn(s)))\n\n const perScenario = input.originals.map((s, i) => ({\n scenarioId: input.scenarioId(s),\n originalScore: origScores[i]!,\n perturbedScore: pertScores[i]!,\n delta: pertScores[i]! - origScores[i]!,\n qValue: NaN,\n }))\n\n // Drop scenarios below the floor (partial failures we don't trust).\n const valid = perScenario.filter((p) => p.originalScore >= floor && p.perturbedScore >= floor)\n if (valid.length < 4) {\n return {\n perScenario,\n pairedTest: { w: 0, p: 1 },\n medianDelta: 0,\n meanDelta: 0,\n contaminationSuspected: false,\n reason: `insufficient valid scenarios (n=${valid.length}, need ≥ 4)`,\n n: valid.length,\n }\n }\n\n const origValid = valid.map((p) => p.originalScore)\n const pertValid = valid.map((p) => p.perturbedScore)\n const pairedTest = wilcoxonSignedRank(origValid, pertValid)\n const deltas = valid.map((p) => p.delta)\n const sortedDeltas = [...deltas].sort((a, b) => a - b)\n const median = sortedDeltas[Math.floor(sortedDeltas.length / 2)]!\n const mean = deltas.reduce((s, d) => s + d, 0) / deltas.length\n\n // Per-scenario q-values via BH on a synthetic per-scenario p-value\n // (one-sample bootstrap; we use the absolute delta normalized by median\n // as a coarse signal — this is a display aid, the load-bearing test\n // is the global Wilcoxon).\n const pseudoP = valid.map((p) => Math.min(1, Math.max(1e-6, 1 - Math.abs(p.delta) / 1)))\n const { qValues } = benjaminiHochberg(pseudoP, fdr)\n for (let i = 0; i < valid.length; i++) {\n const v = valid[i]!\n const idx = perScenario.findIndex((p) => p.scenarioId === v.scenarioId)\n if (idx >= 0) perScenario[idx]!.qValue = qValues[i]!\n }\n\n const contaminationSuspected = pairedTest.p < fdr && median <= -minMedianDrop\n const reason = contaminationSuspected\n ? `paired p=${pairedTest.p.toFixed(4)} < ${fdr} and median drop ${median.toFixed(4)} ≥ ${minMedianDrop}`\n : pairedTest.p >= fdr\n ? `no significant difference (paired p=${pairedTest.p.toFixed(4)})`\n : `significant but small effect (median delta ${median.toFixed(4)})`\n\n return {\n perScenario,\n pairedTest,\n medianDelta: median,\n meanDelta: mean,\n contaminationSuspected,\n reason,\n n: valid.length,\n }\n}\n\n// ── Stock perturbations ──────────────────────────────────────────────────\n\n/**\n * Identifier-rename perturbation for code/text scenarios. Replaces every\n * occurrence of the listed identifiers with synthesized aliases. Use when\n * the scenario's structural difficulty is independent of variable names\n * (e.g. SWE-Bench-style coding tasks).\n */\nexport function renameVariables<S extends { prompt: string }>(\n identifiers: string[],\n rename: (name: string, idx: number) => string = (n, i) => `${n}_${((i % 26) + 10).toString(36)}`,\n): ScenarioPerturbation<S> {\n return {\n kind: 'rename_variables',\n apply(scenario) {\n let prompt = scenario.prompt\n identifiers.forEach((id, i) => {\n const replacement = rename(id, i)\n const re = new RegExp(`\\\\b${escapeRegex(id)}\\\\b`, 'g')\n prompt = prompt.replace(re, replacement)\n })\n return { ...scenario, prompt }\n },\n }\n}\n\n/**\n * Order-shuffle perturbation. Reshuffles a list-shaped section of the\n * prompt (for QA scenarios that present options A/B/C/D — answer depends\n * on the option labels, not order). Caller provides the section extractor.\n */\nexport function shuffleOrder<S extends { prompt: string }>(\n shuffleSection: (prompt: string, rng: () => number) => string,\n seed: number,\n): ScenarioPerturbation<S> {\n let s = seed >>> 0\n const rng = (): number => {\n s = (s + 0x6d2b79f5) >>> 0\n let t = s\n t = Math.imul(t ^ (t >>> 15), t | 1)\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61)\n return ((t ^ (t >>> 14)) >>> 0) / 4294967296\n }\n return {\n kind: 'shuffle_order',\n apply(scenario) {\n const newPrompt = shuffleSection(scenario.prompt, rng)\n return { ...scenario, prompt: newPrompt }\n },\n }\n}\n\n/**\n * Inject-irrelevant-clause perturbation. Adds a benign sentence that\n * shouldn't change the answer. Tests for \"did the model just memorize\n * the input string.\"\n */\nexport function injectIrrelevantClause<S extends { prompt: string }>(\n clause: string,\n position: 'prefix' | 'suffix' = 'prefix',\n): ScenarioPerturbation<S> {\n return {\n kind: 'inject_irrelevant_clause',\n apply(scenario) {\n const prompt =\n position === 'prefix' ? `${clause} ${scenario.prompt}` : `${scenario.prompt} ${clause}`\n return { ...scenario, prompt }\n },\n }\n}\n\n// ── Helpers ──────────────────────────────────────────────────────────────\n\nfunction escapeRegex(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n","/**\n * RL corpus — the durable, append-only accumulation of graded RunRecords that\n * every eval run deposits BY DEFAULT.\n *\n * The dataset is the free exhaust of the normal eval process: we run evals\n * constantly to get an agent production-ready, and those runs already produce\n * graded trajectories. Instead of writing them to an ephemeral run dir and\n * throwing them away, `appendToCorpus` accumulates them into a durable corpus;\n * `buildDatasetFromCorpus` later harvests the whole corpus into a publishable\n * bundle. No separate data-collection campaign — the data accrues from work we\n * do anyway. This is the \"best things for free by our process\" layer.\n *\n * Trajectory text rides on the record as top-level `prompt` / `completion`\n * (what the eval harnesses capture; the RunRecord validator ignores the extra\n * keys). The harvest reads them directly — no trace store round-trip needed.\n */\n\nimport { appendFileSync, existsSync, mkdirSync, readFileSync } from 'node:fs'\nimport { dirname } from 'node:path'\nimport type { RunRecord } from '../run-record'\nimport { buildRlDataset, type RlDatasetBundle, type RlDatasetConfig } from './dataset'\n\n/** A corpus record is a RunRecord carrying the trajectory text the harness\n * captured. `prompt`/`completion` are top-level (the validator ignores extras). */\nexport type CorpusRecord = RunRecord & { prompt?: string; completion?: string }\n\nexport interface CorpusAppendResult {\n appended: number\n /** Skipped because a record with the same runId was already in the corpus\n * (idempotent appends — NOT re-run collapsing; re-runs get fresh runIds). */\n skipped: number\n total: number\n}\n\n/**\n * Append graded records to the corpus (append-only JSONL). Deduplicates by\n * `runId` against what's already on disk so re-running the same harness is\n * idempotent. Creates the file and parent dir. This is the call every eval\n * harness makes by default after producing its records.\n */\nexport function appendToCorpus(records: CorpusRecord[], corpusPath: string): CorpusAppendResult {\n mkdirSync(dirname(corpusPath), { recursive: true })\n const existing = existsSync(corpusPath) ? readCorpus(corpusPath) : []\n const seen = new Set(existing.map((r) => r.runId))\n const lines: string[] = []\n let appended = 0\n let skipped = 0\n for (const r of records) {\n if (seen.has(r.runId)) {\n skipped++\n continue\n }\n seen.add(r.runId)\n lines.push(JSON.stringify(r))\n appended++\n }\n if (lines.length > 0) appendFileSync(corpusPath, `${lines.join('\\n')}\\n`)\n return { appended, skipped, total: existing.length + appended }\n}\n\n/** Read the full corpus. Returns [] if the corpus does not exist yet. */\nexport function readCorpus(corpusPath: string): CorpusRecord[] {\n if (!existsSync(corpusPath)) return []\n const out: CorpusRecord[] = []\n for (const line of readFileSync(corpusPath, 'utf8').split('\\n')) {\n if (line.trim()) out.push(JSON.parse(line) as CorpusRecord)\n }\n return out\n}\n\nfunction rewardOf(r: CorpusRecord): number {\n const v = r.outcome.holdoutScore ?? r.outcome.searchScore\n return typeof v === 'number' && Number.isFinite(v) ? v : 0\n}\n\nexport interface HarvestOptions {\n /** Keep only records scoring >= this (rejection-sampling for SFT). */\n minScore?: number\n /** Keep only these splits (e.g. ['holdout'] for an eval-only dataset). */\n splits?: RunRecord['splitTag'][]\n}\n\n/**\n * Harvest the accumulated corpus into a publishable RL dataset bundle. Reads\n * trajectory text from each record's top-level `prompt`/`completion`; records\n * missing either are excluded (a graded score with no trajectory can't train).\n * Optionally filters by score / split. Throws (via buildRlDataset) if nothing\n * survives — an empty dataset must never be published.\n */\nexport async function buildDatasetFromCorpus(\n corpusPath: string,\n config: RlDatasetConfig,\n opts: HarvestOptions = {},\n): Promise<RlDatasetBundle> {\n let records = readCorpus(corpusPath).filter(\n (r) => typeof r.prompt === 'string' && typeof r.completion === 'string',\n )\n if (opts.splits) records = records.filter((r) => opts.splits!.includes(r.splitTag))\n if (opts.minScore != null) records = records.filter((r) => rewardOf(r) >= opts.minScore!)\n\n const text = new Map(\n records.map((r) => [r.runId, { prompt: r.prompt!, completion: r.completion! }]),\n )\n const lookups = {\n promptOf: (id: string) => text.get(id)?.prompt ?? '',\n completionOf: (id: string) => text.get(id)?.completion ?? '',\n }\n return buildRlDataset(records, lookups, config)\n}\n","/**\n * Trainer-format exporters.\n *\n * agent-eval produces canonical artifacts (`RunRecord[]`, `PreferenceTriple[]`,\n * `StepReward[]`, `PrmTrainingTriple[]`). RL training pipelines consume\n * different shapes — Hugging Face TRL, Prime Intellect's prime-rl, OpenAI\n * fine-tuning, Anthropic finetuning, OpenRLHF, verl. Each has its own\n * JSONL conventions. Rather than ship N adapters, this module ships the\n * canonical formats most production pipelines accept and ergonomic helpers\n * for the rest.\n *\n * Shapes:\n * - **DPO / IPO / KTO** — `{prompt, chosen, rejected}` JSONL. Consumed\n * by HuggingFace TRL, prime-rl's offline DPO, OpenRLHF.\n * - **GRPO offline** — `{prompt, completions[], rewards[]}` JSONL.\n * Consumed by prime-rl GRPO, verl, OpenRLHF.\n * - **SFT** — `{messages[]}` JSONL with chosen completion as the final\n * assistant turn. Consumed by HF SFT trainers, OpenAI fine-tuning,\n * Anthropic finetuning.\n * - **PRM** — `{prompt, prefix_steps[], chosen_step, rejected_step}` JSONL.\n * Consumed by Lightman-style PRM trainers and prime-rl's PRM mode.\n *\n * Why ship this in agent-eval rather than a separate adapter package: the\n * canonical artifacts (`RunRecord[]`, `PreferenceTriple[]`, etc.) are\n * agent-eval's contract; without first-party exporters consumers reverse-\n * engineer the mapping every release. The exporters codify it.\n *\n * The exporters take callbacks for any field that isn't on the canonical\n * artifact (specifically: prompt + completion text, since the package\n * stores only their hashes by design — full text is the consumer's\n * trace store / raw event log).\n */\n\nimport type { RunRecord } from '../run-record'\nimport type { PreferenceTriple } from './preferences'\nimport type { PrmTrainingTriple, StepReward } from './process-reward'\n\n// ── DPO / IPO / KTO ──────────────────────────────────────────────────────\n\nexport interface DpoLookups {\n /** Resolve the prompt text for a run (typically from a trace store / raw event sink). */\n promptOf: (runId: string) => string | Promise<string>\n /** Resolve the assistant completion text for a run. */\n completionOf: (runId: string) => string | Promise<string>\n}\n\nexport interface DpoExportRow {\n prompt: string\n chosen: string\n rejected: string\n /** Carried-through margin. Some KTO / IPO variants use this. */\n margin?: number\n /** Free-form metadata for downstream filtering / sharding. */\n meta?: Record<string, unknown>\n}\n\n/**\n * Convert preference triples to TRL-compatible DPO rows. The shape\n * `{prompt, chosen, rejected}` is the canonical HuggingFace DPODataset\n * entry; every major DPO trainer accepts it.\n */\nexport async function toDpoRows(\n triples: PreferenceTriple[],\n lookups: DpoLookups,\n): Promise<DpoExportRow[]> {\n const out: DpoExportRow[] = []\n for (const t of triples) {\n const [prompt, chosen, rejected] = await Promise.all([\n Promise.resolve(lookups.promptOf(t.chosenRunId)),\n Promise.resolve(lookups.completionOf(t.chosenRunId)),\n Promise.resolve(lookups.completionOf(t.rejectedRunId)),\n ])\n out.push({\n prompt,\n chosen,\n rejected,\n margin: t.marginScore,\n meta: {\n scenarioId: t.scenarioId,\n chosenVariantId: t.chosenVariantId,\n rejectedVariantId: t.rejectedVariantId,\n chosenRunId: t.chosenRunId,\n rejectedRunId: t.rejectedRunId,\n chosenModel: t.meta.chosenModel,\n rejectedModel: t.meta.rejectedModel,\n },\n })\n }\n return out\n}\n\n/** Serialize DPO rows as JSONL. One line per row. */\nexport function toDpoJsonl(rows: DpoExportRow[]): string {\n return rows.map((r) => JSON.stringify(r)).join('\\n') + (rows.length > 0 ? '\\n' : '')\n}\n\n// ── GRPO offline ─────────────────────────────────────────────────────────\n\nexport interface GrpoLookups {\n promptOf: (runId: string) => string | Promise<string>\n completionOf: (runId: string) => string | Promise<string>\n /** Optional: derive a custom reward from the run. Defaults to score. */\n rewardOf?: (run: RunRecord) => number | null\n}\n\nexport interface GrpoExportRow {\n prompt: string\n completions: string[]\n rewards: number[]\n /** runIds in the same order as `completions[]` for traceability. */\n runIds: string[]\n meta?: Record<string, unknown>\n}\n\n/**\n * Convert RunRecord[] grouped by `(scenarioId)` into GRPO offline rows —\n * one row per scenario, with one completion per run on that scenario.\n *\n * GRPO (Shao et al. 2024 / DeepSeek-R1) trains on relative advantages\n * within a group of completions for the same prompt; this is the\n * canonical input format.\n */\nexport async function toGrpoRows(\n runs: RunRecord[],\n lookups: GrpoLookups,\n): Promise<GrpoExportRow[]> {\n const rewardOf = lookups.rewardOf ?? defaultReward\n const grouped = new Map<string, RunRecord[]>()\n for (const r of runs) {\n const sid = r.scenarioId ?? r.experimentId\n const arr = grouped.get(sid) ?? []\n arr.push(r)\n grouped.set(sid, arr)\n }\n\n const rows: GrpoExportRow[] = []\n for (const [scenarioId, group] of grouped.entries()) {\n if (group.length === 0) continue\n // Resolve prompt once per group (assumes all runs in a group share the prompt).\n const prompt = await Promise.resolve(lookups.promptOf(group[0]!.runId))\n const completions: string[] = []\n const rewards: number[] = []\n const runIds: string[] = []\n for (const r of group) {\n const reward = rewardOf(r)\n if (reward === null) continue\n const completion = await Promise.resolve(lookups.completionOf(r.runId))\n completions.push(completion)\n rewards.push(reward)\n runIds.push(r.runId)\n }\n if (completions.length === 0) continue\n rows.push({\n prompt,\n completions,\n rewards,\n runIds,\n meta: {\n scenarioId,\n n: completions.length,\n meanReward: rewards.reduce((s, x) => s + x, 0) / rewards.length,\n },\n })\n }\n return rows\n}\n\nexport function toGrpoJsonl(rows: GrpoExportRow[]): string {\n return rows.map((r) => JSON.stringify(r)).join('\\n') + (rows.length > 0 ? '\\n' : '')\n}\n\n// ── SFT ──────────────────────────────────────────────────────────────────\n\nexport interface SftLookups {\n promptOf: (runId: string) => string | Promise<string>\n completionOf: (runId: string) => string | Promise<string>\n /** Optional system message. Default omits. */\n systemOf?: (run: RunRecord) => string | null | undefined\n /** Filter — return false to skip the run (e.g., low score, failed cases). */\n include?: (run: RunRecord) => boolean\n}\n\nexport interface SftExportRow {\n messages: Array<{ role: 'system' | 'user' | 'assistant'; content: string }>\n meta?: Record<string, unknown>\n}\n\n/**\n * Convert RunRecord[] into Hugging Face / OpenAI / Anthropic-style\n * conversational SFT rows. By default every record becomes one row;\n * pass `include` to filter (e.g., keep only `score >= 0.8` for\n * rejection-sampling SFT).\n */\nexport async function toSftRows(runs: RunRecord[], lookups: SftLookups): Promise<SftExportRow[]> {\n const include = lookups.include ?? (() => true)\n const rows: SftExportRow[] = []\n for (const r of runs) {\n if (!include(r)) continue\n const system = lookups.systemOf?.(r)\n const [prompt, completion] = await Promise.all([\n Promise.resolve(lookups.promptOf(r.runId)),\n Promise.resolve(lookups.completionOf(r.runId)),\n ])\n const messages: SftExportRow['messages'] = []\n if (system) messages.push({ role: 'system', content: system })\n messages.push({ role: 'user', content: prompt })\n messages.push({ role: 'assistant', content: completion })\n rows.push({\n messages,\n meta: {\n runId: r.runId,\n candidateId: r.candidateId,\n scenarioId: r.scenarioId,\n score: r.outcome.holdoutScore ?? r.outcome.searchScore,\n model: r.model,\n },\n })\n }\n return rows\n}\n\nexport function toSftJsonl(rows: SftExportRow[]): string {\n return rows.map((r) => JSON.stringify(r)).join('\\n') + (rows.length > 0 ? '\\n' : '')\n}\n\n// ── PRM ──────────────────────────────────────────────────────────────────\n\nexport interface PrmLookups {\n /** Resolve the prompt text for a run. */\n promptOf: (runId: string) => string | Promise<string>\n /** Resolve the trajectory step text for a (runId, spanId) pair. */\n stepTextOf: (runId: string, spanId: string) => string | Promise<string>\n /** Optional: sequence of prefix span ids leading up to the divergence. */\n prefixOf?: (runId: string, prefixStepIndex: number) => string[] | Promise<string[]>\n}\n\nexport interface PrmExportRow {\n prompt: string\n /** Span ids for the steps before divergence — caller resolves text via `stepTextOf`. */\n prefixSpanIds: string[]\n prefixStepText: string[]\n chosenStep: string\n rejectedStep: string\n chosenReward: number\n rejectedReward: number\n marginScore: number\n meta?: Record<string, unknown>\n}\n\n/**\n * Convert PRM training triples to JSONL rows. Caller's `stepTextOf`\n * callback resolves span text from the consumer's trace store.\n */\nexport async function toPrmRows(\n triples: PrmTrainingTriple[],\n lookups: PrmLookups,\n): Promise<PrmExportRow[]> {\n const rows: PrmExportRow[] = []\n for (const t of triples) {\n const prompt = await Promise.resolve(lookups.promptOf(t.prefixRunId))\n const prefixSpanIds = lookups.prefixOf\n ? await Promise.resolve(lookups.prefixOf(t.prefixRunId, t.prefixStepIndex))\n : []\n const prefixStepText: string[] = []\n for (const spanId of prefixSpanIds) {\n prefixStepText.push(await Promise.resolve(lookups.stepTextOf(t.prefixRunId, spanId)))\n }\n const chosenStep = await Promise.resolve(lookups.stepTextOf(t.prefixRunId, t.chosenSpanId))\n const rejectedStep = await Promise.resolve(\n lookups.stepTextOf(t.rejectedRunId, t.rejectedSpanId),\n )\n rows.push({\n prompt,\n prefixSpanIds,\n prefixStepText,\n chosenStep,\n rejectedStep,\n chosenReward: t.chosenReward,\n rejectedReward: t.rejectedReward,\n marginScore: t.marginScore,\n meta: {\n prefixRunId: t.prefixRunId,\n rejectedRunId: t.rejectedRunId,\n prefixStepIndex: t.prefixStepIndex,\n },\n })\n }\n return rows\n}\n\nexport function toPrmJsonl(rows: PrmExportRow[]): string {\n return rows.map((r) => JSON.stringify(r)).join('\\n') + (rows.length > 0 ? '\\n' : '')\n}\n\n// ── Step rewards (for value-function regression) ─────────────────────────\n\nexport interface StepRewardJsonlRow {\n runId: string\n spanId: string\n stepIndex: number\n reward: number\n determinism: 'deterministic' | 'probabilistic'\n weight: number\n}\n\nexport function stepRewardsToJsonl(stepRewards: StepReward[]): string {\n const rows: StepRewardJsonlRow[] = stepRewards.map((s) => ({\n runId: s.runId,\n spanId: s.spanId,\n stepIndex: s.stepIndex,\n reward: s.reward,\n determinism: s.determinism,\n weight: s.weight ?? 1,\n }))\n return rows.map((r) => JSON.stringify(r)).join('\\n') + (rows.length > 0 ? '\\n' : '')\n}\n\n// ── Helpers ──────────────────────────────────────────────────────────────\n\nfunction defaultReward(run: RunRecord): number | null {\n const v = run.outcome.holdoutScore ?? run.outcome.searchScore\n return typeof v === 'number' && Number.isFinite(v) ? v : null\n}\n","/**\n * RL dataset packaging + datasheet — the publishable, sellable bundle.\n *\n * The format exporters (`toGrpoRows` / `toSftRows` / `toDpoRows`) already\n * produce trainer-ready shapes (prime-rl GRPO, TRL DPO, conversational SFT).\n * What turns that into a dataset someone can PUBLISH or BUY is the provenance\n * + a datasheet: which models produced it, which prompt/agent versions, how the\n * reward was derived (deterministic verifiable vs probabilistic judge — the\n * credibility axis a buyer checks first), the split discipline, the reward\n * distribution, the quality gates, the license, and the intended/out-of-scope\n * uses. This module computes those facts from the `RunRecord[]` and renders a\n * \"Datasheet for Datasets\" (Gebru et al. 2018) card alongside the format files.\n *\n * It composes the existing `rl/exporters` — it does not reimplement any trainer\n * format. The renderers token-identity step (DeepSeek/Kimi/Qwen tokenization\n * with per-token loss masks) is a downstream Python stage that consumes the\n * `messages`/`completions` this bundle emits.\n */\n\nimport type { RunRecord, RunSplitTag } from '../run-record'\nimport {\n type DpoLookups,\n type GrpoLookups,\n type SftLookups,\n toDpoJsonl,\n toDpoRows,\n toGrpoJsonl,\n toGrpoRows,\n toSftJsonl,\n toSftRows,\n} from './exporters'\nimport type { PreferenceTriple } from './preferences'\n\nexport type RewardKind = 'deterministic' | 'probabilistic' | 'mixed'\nexport type DatasetFormat = 'grpo' | 'sft' | 'dpo'\n\n/** Caller-declared context — the qualitative half of the datasheet that can't\n * be computed from records. */\nexport interface RlDatasetConfig {\n name: string\n version: string\n /** Product/task domain, e.g. 'legal-m&a', 'tax-1040'. */\n domain: string\n /** SPDX id or a named commercial license. Required — an unlicensed dataset\n * cannot be published or sold. */\n license: string\n /** How the reward was produced. `kind: 'deterministic'` (a test/schema/XPath\n * decided it) is the credibility signal; 'probabilistic' = LLM-judge. */\n reward: { kind: RewardKind; source: string; description: string }\n intendedUse: string\n outOfScope: string\n limitations: string\n /** ISO timestamp — passed in (the substrate forbids Date.now()). */\n createdAtIso: string\n /** Default: ['grpo', 'sft']. */\n formats?: DatasetFormat[]\n /** Quality gates already run, recorded on the card for the buyer. */\n qualityGates?: {\n contaminationProbe?: 'passed' | 'failed' | 'not-run'\n dedup?: boolean\n verifiableRewardFilter?: boolean\n }\n}\n\nexport interface RewardStats {\n n: number\n mean: number\n median: number\n min: number\n max: number\n std: number\n}\n\nexport interface RlDatasetStats {\n records: number\n /** Record count per split — a publishable dataset must declare its holdout. */\n splits: Record<RunSplitTag, number>\n reward: RewardStats\n /** Distinct snapshot-pinned models that produced the trajectories. */\n models: string[]\n /** Distinct effective-prompt hashes (the agent profile/prompt versions). */\n promptHashes: string[]\n commitShas: string[]\n totalTokens: { input: number; output: number }\n totalCostUsd: number\n}\n\nexport interface RlDatasetManifest extends RlDatasetConfig {\n formats: DatasetFormat[]\n rowCounts: Partial<Record<DatasetFormat, number>>\n stats: RlDatasetStats\n}\n\nexport interface RlDatasetBundle {\n manifest: RlDatasetManifest\n /** Relative filename -> contents. Write these to a directory to publish. */\n files: Record<string, string>\n}\n\nfunction reward(r: RunRecord): number | null {\n const v = r.outcome.holdoutScore ?? r.outcome.searchScore\n return typeof v === 'number' && Number.isFinite(v) ? v : null\n}\n\nfunction distinct(xs: string[]): string[] {\n return [...new Set(xs)].sort()\n}\n\nfunction computeRewardStats(values: number[]): RewardStats {\n if (values.length === 0) return { n: 0, mean: 0, median: 0, min: 0, max: 0, std: 0 }\n const sorted = [...values].sort((a, b) => a - b)\n const n = sorted.length\n const mean = sorted.reduce((s, x) => s + x, 0) / n\n const mid = Math.floor(n / 2)\n const median = n % 2 === 0 ? (sorted[mid - 1]! + sorted[mid]!) / 2 : sorted[mid]!\n const variance = sorted.reduce((s, x) => s + (x - mean) ** 2, 0) / n\n return { n, mean, median, min: sorted[0]!, max: sorted[n - 1]!, std: Math.sqrt(variance) }\n}\n\nfunction computeStats(records: RunRecord[]): RlDatasetStats {\n const splits: Record<RunSplitTag, number> = { search: 0, dev: 0, holdout: 0 }\n let inTok = 0\n let outTok = 0\n let cost = 0\n const rewards: number[] = []\n for (const r of records) {\n splits[r.splitTag] = (splits[r.splitTag] ?? 0) + 1\n inTok += r.tokenUsage.input\n outTok += r.tokenUsage.output\n cost += r.costUsd\n const rw = reward(r)\n if (rw !== null) rewards.push(rw)\n }\n return {\n records: records.length,\n splits,\n reward: computeRewardStats(rewards),\n models: distinct(records.map((r) => r.model)),\n promptHashes: distinct(records.map((r) => r.promptHash)),\n commitShas: distinct(records.map((r) => r.commitSha)),\n totalTokens: { input: inTok, output: outTok },\n totalCostUsd: cost,\n }\n}\n\n/**\n * Package graded `RunRecord[]` into a publishable RL dataset bundle: the\n * trainer-format JSONL files + a manifest + a datasheet. DPO requires\n * pre-extracted preference triples (pass `preferences`); GRPO/SFT derive from\n * the records directly via the supplied lookups. Throws on an empty corpus —\n * an empty dataset must never be published.\n */\nexport async function buildRlDataset(\n records: RunRecord[],\n lookups: GrpoLookups & SftLookups,\n config: RlDatasetConfig,\n preferences?: { triples: PreferenceTriple[]; lookups: DpoLookups },\n): Promise<RlDatasetBundle> {\n if (records.length === 0) {\n throw new Error('buildRlDataset: no records — refusing to package an empty dataset')\n }\n const formats = config.formats ?? ['grpo', 'sft']\n const files: Record<string, string> = {}\n const rowCounts: Partial<Record<DatasetFormat, number>> = {}\n\n if (formats.includes('grpo')) {\n const rows = await toGrpoRows(records, lookups)\n files['train.grpo.jsonl'] = toGrpoJsonl(rows)\n rowCounts.grpo = rows.length\n }\n if (formats.includes('sft')) {\n const rows = await toSftRows(records, lookups)\n files['train.sft.jsonl'] = toSftJsonl(rows)\n rowCounts.sft = rows.length\n }\n if (formats.includes('dpo')) {\n if (!preferences) {\n throw new Error(\"buildRlDataset: format 'dpo' requires `preferences` (triples + lookups)\")\n }\n const rows = await toDpoRows(preferences.triples, preferences.lookups)\n files['train.dpo.jsonl'] = toDpoJsonl(rows)\n rowCounts.dpo = rows.length\n }\n\n const manifest: RlDatasetManifest = {\n ...config,\n formats,\n rowCounts,\n stats: computeStats(records),\n }\n files['manifest.json'] = `${JSON.stringify(manifest, null, 2)}\\n`\n files['DATASHEET.md'] = datasheetToMarkdown(manifest)\n return { manifest, files }\n}\n\nfunction pct(x: number): string {\n return `${(x * 100).toFixed(1)}%`\n}\n\n/** Render the \"Datasheet for Datasets\" card — the artifact a buyer reads. */\nexport function datasheetToMarkdown(m: RlDatasetManifest): string {\n const s = m.stats\n const total = s.records || 1\n const splitLines = (['search', 'dev', 'holdout'] as RunSplitTag[])\n .map((k) => ` - \\`${k}\\`: ${s.splits[k]} (${pct(s.splits[k] / total)})`)\n .join('\\n')\n const deterministic = m.reward.kind === 'deterministic'\n return [\n `# Dataset: ${m.name} \\`v${m.version}\\``,\n '',\n `**Domain:** ${m.domain} · **Created:** ${m.createdAtIso} · **License:** ${m.license}`,\n '',\n '## Reward provenance',\n `- **Kind:** ${m.reward.kind}${deterministic ? ' ✅ (decidable — not judge-noise)' : ''}`,\n `- **Source:** ${m.reward.source}`,\n `- **Description:** ${m.reward.description}`,\n '',\n '## Composition',\n `- **Records (trajectories):** ${s.records}`,\n `- **Formats:** ${m.formats.map((f) => `${f} (${m.rowCounts[f] ?? 0} rows)`).join(', ')}`,\n '- **Splits:**',\n splitLines,\n '',\n '## Reward distribution',\n `- n=${s.reward.n} · mean=${s.reward.mean.toFixed(3)} · median=${s.reward.median.toFixed(3)} · min=${s.reward.min.toFixed(3)} · max=${s.reward.max.toFixed(3)} · std=${s.reward.std.toFixed(3)}`,\n '',\n '## Provenance',\n `- **Models:** ${s.models.join(', ')}`,\n `- **Prompt/agent versions (sha256):** ${s.promptHashes.length} distinct`,\n `- **Commits:** ${s.commitShas.join(', ')}`,\n `- **Tokens:** ${s.totalTokens.input} in / ${s.totalTokens.output} out · **Cost:** $${s.totalCostUsd.toFixed(2)}`,\n '',\n '## Quality gates',\n `- Contamination probe: ${m.qualityGates?.contaminationProbe ?? 'not-run'}`,\n `- Dedup: ${m.qualityGates?.dedup ? 'yes' : 'no'} · Verifiable-reward filter: ${m.qualityGates?.verifiableRewardFilter ? 'yes' : 'no'}`,\n '',\n '## Recommended uses',\n m.intendedUse,\n '',\n '## Out of scope',\n m.outOfScope,\n '',\n '## Limitations',\n m.limitations,\n '',\n '## Token rendering',\n 'For RL/SFT training, tokenize with the per-model renderer (DeepSeek-V3 / Kimi-K2 / Qwen3) to preserve token identity and per-token loss masks across tool-call turns — see `renderers` (PrimeIntellect). The `messages` / `completions` here are the renderer input.',\n '',\n ].join('\\n')\n}\n","/**\n * `PredictiveValidityResearcher` — concrete `Researcher` implementation\n * that drives selection from outcome-anchored predictive validity.\n *\n * Each method:\n *\n * - `inspectFailures(runs)` — synthesizes failure modes from the\n * bottom-quartile of `RunRecord`s on the configured proxy reward.\n * - `proposeChange(failures)` — proposes steering changes that target\n * the rubrics with the lowest predictive validity (decorative ones).\n * Either reduce their weight in the composite, or recalibrate them.\n * - `applyChange(changes, baseline)` — merges the proposed steering\n * into the experiment plan.\n * - `evaluateChange(plan)` — re-runs the predictive-validity check on\n * the post-change runs and reports the delta.\n *\n * The result is a closed loop: the rubric weights drift toward the ones\n * that actually predict deployment outcomes, automatically. Pair with\n * `runRLCampaign` for the full auto-research story.\n */\n\nimport type { GateDecision } from '../held-out-gate'\nimport type { OutcomeStore } from '../meta-eval/outcome-store'\nimport {\n type RubricPredictiveValidityReport,\n rubricPredictiveValidity,\n} from '../meta-eval/rubric-predictive-validity'\nimport type {\n ExperimentPlan,\n ExperimentResult,\n FailureMode,\n Researcher,\n SteeringChange,\n} from '../researcher'\nimport type { RunRecord } from '../run-record'\n\nexport interface PredictiveValidityResearcherOptions {\n outcomes: OutcomeStore\n outcomeMetrics: string[]\n /** Score threshold below which a run counts as a \"failure.\" Default 0.5. */\n failureThreshold?: number\n /** Spearman bucket below which a rubric is \"decorative.\" Default 0.4. */\n decorativeThreshold?: number\n /** Optional steering-namespace prefix for proposed changes. Default `'rubric_weight'`. */\n steeringNamespace?: string\n /** Override the rubric set the researcher inspects. Default: every numeric `outcome.raw` key seen. */\n rubrics?: string[]\n /**\n * Snapshot stash hook — called with the most recent predictive-validity\n * report. Useful when a downstream system wants to log rubric drift over\n * time. Default no-op.\n */\n onReport?: (report: RubricPredictiveValidityReport) => void | Promise<void>\n}\n\n/**\n * Concrete `Researcher` driven by `rubricPredictiveValidity`. The brain:\n * rubrics that don't predict deployment outcomes don't earn weight.\n */\nexport class PredictiveValidityResearcher implements Researcher {\n private opts: PredictiveValidityResearcherOptions\n private lastReport: RubricPredictiveValidityReport | null = null\n\n constructor(opts: PredictiveValidityResearcherOptions) {\n this.opts = opts\n }\n\n async inspectFailures(runs: RunRecord[]): Promise<FailureMode[]> {\n const threshold = this.opts.failureThreshold ?? 0.5\n const failures: FailureMode[] = []\n const failingRuns = runs.filter((r) => {\n const score = r.outcome.holdoutScore ?? r.outcome.searchScore\n return typeof score === 'number' && score < threshold\n })\n if (failingRuns.length === 0) return failures\n\n // Group failures by candidateId — the researcher's primary handle is\n // \"this candidate is producing low-scoring outputs in this scenario.\"\n const grouped = new Map<string, RunRecord[]>()\n for (const r of failingRuns) {\n const arr = grouped.get(r.candidateId) ?? []\n arr.push(r)\n grouped.set(r.candidateId, arr)\n }\n\n for (const [candidateId, group] of grouped.entries()) {\n const meanScore =\n group.reduce((s, r) => {\n const x = r.outcome.holdoutScore ?? r.outcome.searchScore ?? 0\n return s + x\n }, 0) / group.length\n failures.push({\n code: `low-score-${candidateId}`,\n description: `${candidateId} scored < ${threshold} on ${group.length} run(s) (mean ${meanScore.toFixed(3)})`,\n evidence: {\n runIds: group.slice(0, 8).map((r) => r.runId),\n samples: group.length,\n },\n })\n }\n return failures\n }\n\n async proposeChange(failures: FailureMode[]): Promise<SteeringChange[]> {\n if (failures.length === 0) return []\n\n // Without a prior report, return a single \"collect more outcome data\"\n // change — the researcher refuses to reweight rubrics from zero evidence.\n if (this.lastReport === null) {\n return [\n {\n kind: 'threshold',\n payload: { directive: 'researcher.collect-more-outcomes' },\n rationale:\n 'predictive-validity researcher has no prior report; cannot recommend rubric reweighting until at least one report exists',\n },\n ]\n }\n\n const decorativeThreshold = this.opts.decorativeThreshold ?? 0.4\n const changes: SteeringChange[] = []\n\n for (const ranking of this.lastReport.ranked) {\n if (ranking.verdict === 'load_bearing') continue\n if (Math.abs(ranking.spearman) >= decorativeThreshold) continue\n changes.push({\n kind: 'reviewer_prompt',\n payload: {\n rubric: ranking.rubric,\n action: 'down-weight',\n spearman: ranking.spearman,\n bestOutcome: ranking.bestOutcome,\n },\n rationale: `predictive-validity Spearman=${ranking.spearman.toFixed(3)} vs ${ranking.bestOutcome} (decorative); recommend down-weighting`,\n expectedDelta: -Math.max(0, 0.05 - Math.abs(ranking.spearman)),\n })\n }\n for (const ranking of this.lastReport.ranked.slice(0, 1)) {\n if (ranking.verdict !== 'load_bearing') continue\n changes.push({\n kind: 'reviewer_prompt',\n payload: {\n rubric: ranking.rubric,\n action: 'up-weight',\n spearman: ranking.spearman,\n bestOutcome: ranking.bestOutcome,\n },\n rationale: `predictive-validity Spearman=${ranking.spearman.toFixed(3)} vs ${ranking.bestOutcome} (load-bearing); recommend up-weighting`,\n expectedDelta: Math.max(0, Math.abs(ranking.spearman) - 0.5) * 0.1,\n })\n }\n return changes\n }\n\n async applyChange(changes: SteeringChange[], baseline: ExperimentPlan): Promise<ExperimentPlan> {\n // Merge proposed changes into the plan's `changes` array, preserving\n // any changes the baseline already had.\n return {\n ...baseline,\n changes: [...baseline.changes, ...changes],\n }\n }\n\n async evaluateChange(plan: ExperimentPlan): Promise<ExperimentResult> {\n // The researcher contract takes a *plan* and returns a *result* —\n // implementations that only understand re-scoring runs can produce a\n // \"no-op\" gate decision and let the caller drive the actual sweep.\n // Real evaluators (CallbackResearcher) execute the plan; we report.\n const emptyGate: GateDecision = {\n promote: false,\n candidateId: plan.proposedCandidateId,\n baselineId: plan.baselineCandidateId,\n evidence: {\n productiveRuns: 0,\n medianPairedDelta: 0,\n pairedCI: { low: 0, high: 0 },\n pairedPValue: 1,\n searchScore: 0,\n holdoutScore: 0,\n overfitGap: 0,\n baselineOverfitGap: 0,\n medianCandidateCost: Number.NaN,\n medianBaselineCost: Number.NaN,\n },\n reason:\n 'predictive-validity researcher does not execute plans; the caller is expected to run the sweep and call rubricPredictiveValidity directly with the resulting RunRecord[].',\n rejectionCode: 'few_runs',\n }\n return {\n plan,\n runs: [],\n gateDecision: emptyGate,\n }\n }\n\n /**\n * Run the predictive-validity check explicitly against a fresh RunRecord\n * set. Updates the researcher's cached report so subsequent\n * `proposeChange` calls have evidence to draw from.\n */\n async runValidityCheck(runs: RunRecord[]): Promise<RubricPredictiveValidityReport> {\n const report = await rubricPredictiveValidity({\n runs,\n outcomes: this.opts.outcomes,\n outcomeMetrics: this.opts.outcomeMetrics,\n rubrics: this.opts.rubrics,\n })\n if (this.opts.onReport) await this.opts.onReport(report)\n this.lastReport = report\n return report\n }\n\n /**\n * Force-feed a predictive-validity report into the researcher state —\n * useful when the consumer ran the report out-of-band and wants the\n * researcher's later proposals informed by it.\n */\n setReport(report: RubricPredictiveValidityReport): void {\n this.lastReport = report\n }\n\n getLastReport(): RubricPredictiveValidityReport | null {\n return this.lastReport\n }\n}\n","/**\n * Preference dataset extraction — bridge from `RunRecord[]` to RL training.\n *\n * Production RLHF / DPO / KTO / SimPO pipelines need preference triples:\n * `(prompt, chosen, rejected)`. The campaign artifact already contains the\n * ingredients — every (variantId, scenarioId, seed) cell is a candidate\n * that ran the same prompt against the same scenario, scored by the same\n * judge — but turning that into a clean preference dataset requires\n * deciding *what counts as a preference*.\n *\n * This module ships three preference-extraction strategies with explicit\n * tradeoffs, plus a unified output type compatible with HuggingFace TRL,\n * Anthropic finetuning JSONL, and OpenAI fine-tuning APIs. The strategies\n * are deliberately not auto-magical — picking the wrong one corrupts the\n * gradient.\n *\n * Strategies:\n *\n * 1. **`paired-by-scenario-and-seed`** — exact-match comparisons. For\n * each scenario × seed pair, compare every (variantA, variantB) on\n * that exact (scenario, seed). Matches scenarios so the comparison\n * isolates variant effects. Highest signal-to-noise; smallest\n * dataset (only matched pairs count).\n *\n * 2. **`paired-by-scenario`** — looser matching. For each scenario,\n * compare every (variantA, variantB) where both have ≥ 1 run on the\n * same scenario. Aggregates across seeds to compute mean scores per\n * (variant, scenario), then forms preferences from the means. More\n * data, lower per-pair signal.\n *\n * 3. **`top-vs-bottom`** — coarsest. Within each scenario, the highest-\n * scoring run is `chosen`, the lowest is `rejected`. Smallest dataset\n * per scenario but biggest score gap per pair. Useful for early\n * bootstrapping when you have few variants.\n *\n * The output `PreferenceTriple` is *agent-eval-canonical* but trivially\n * mappable to TRL's `DPODataset` shape (`prompt`, `chosen`, `rejected`)\n * via the `toTRLFormat` helper.\n */\n\nimport type { RunRecord } from '../run-record'\n\nexport type PreferenceStrategy =\n | 'paired-by-scenario-and-seed'\n | 'paired-by-scenario'\n | 'top-vs-bottom'\n\nexport interface PreferenceTriple {\n /** The scenario (input) the variants were run against. */\n scenarioId: string\n /** RunRecord ids on each side, for traceability. */\n chosenRunId: string\n rejectedRunId: string\n /** Variant ids — load-bearing for the RL update. */\n chosenVariantId: string\n rejectedVariantId: string\n /** The score gap between chosen and rejected. Larger = stronger signal. */\n marginScore: number\n /**\n * Optional `(chosen_score, rejected_score)` pair for soft-margin DPO\n * variants. Omitted for `top-vs-bottom` runs that don't carry meaningful\n * scalar gaps.\n */\n scores?: { chosen: number; rejected: number }\n /** Tie-breaker — when multiple seeds match this scenario, the one used. */\n seed?: number\n /**\n * Free-form metadata propagated from the run records — e.g. original\n * prompt-hash, model, etc. Lets the RL trainer reconstruct the prompt.\n */\n meta: {\n chosenPromptHash: string\n rejectedPromptHash: string\n chosenConfigHash: string\n rejectedConfigHash: string\n chosenModel: string\n rejectedModel: string\n }\n}\n\nexport interface ExtractPreferencesOptions {\n strategy?: PreferenceStrategy\n /**\n * Minimum score gap required to admit a pair. Pairs below this are\n * dropped — they're noise, not signal. Default 0.05 (5% of [0,1]).\n */\n minMargin?: number\n /**\n * Optional split tag filter — restrict to runs from one split. Default\n * `'holdout'` (the canonical \"real\" signal).\n */\n splitTag?: RunRecord['splitTag']\n /**\n * Optional reward extractor that overrides `outcome.holdoutScore` /\n * `outcome.searchScore`. Use to drive preferences off a verifiable\n * reward instead of the headline score.\n */\n rewardOf?: (run: RunRecord) => number | null\n}\n\nexport interface PreferenceExtractionReport {\n pairs: PreferenceTriple[]\n /** Number of (scenario, seed) cells inspected. */\n cellsInspected: number\n /** Number of pairs filtered by `minMargin`. */\n pairsBelowMargin: number\n /** Number of cells with only one variant (no comparison possible). */\n cellsSingleton: number\n /** Strategy used. */\n strategy: PreferenceStrategy\n}\n\nconst SPLIT_TAG_DEFAULT: RunRecord['splitTag'] = 'holdout'\n\nconst DEFAULT_REWARD = (run: RunRecord): number | null => {\n const v = run.outcome.holdoutScore ?? run.outcome.searchScore\n return typeof v === 'number' && Number.isFinite(v) ? v : null\n}\n\n/**\n * Convert `RunRecord[]` to preference triples for RL training.\n *\n * Returns a structured report so callers can see how much data was\n * dropped and why (low-margin pairs, singleton cells). For production\n * pipelines, you usually want to:\n *\n * 1. Run a campaign producing 5–10 variants × 50–200 scenarios × 3 seeds\n * 2. Call this with `strategy: 'paired-by-scenario-and-seed'` and a\n * verifiable-reward extractor as `rewardOf`\n * 3. Pass `report.pairs` to `toTRLFormat` and pipe to your DPO trainer\n */\nexport function extractPreferences(\n runs: RunRecord[],\n opts: ExtractPreferencesOptions = {},\n): PreferenceExtractionReport {\n const strategy = opts.strategy ?? 'paired-by-scenario-and-seed'\n const minMargin = opts.minMargin ?? 0.05\n const splitTag = opts.splitTag ?? SPLIT_TAG_DEFAULT\n const rewardOf = opts.rewardOf ?? DEFAULT_REWARD\n\n const filtered = runs.filter((r) => r.splitTag === splitTag)\n const scoredEntries: Array<{ run: RunRecord; score: number }> = []\n for (const run of filtered) {\n const s = rewardOf(run)\n if (s === null) continue\n scoredEntries.push({ run, score: s })\n }\n\n const pairs: PreferenceTriple[] = []\n let pairsBelowMargin = 0\n let cellsSingleton = 0\n let cellsInspected = 0\n\n if (strategy === 'paired-by-scenario-and-seed') {\n // Group by (scenarioId, seed). Canonical key is `run.scenarioId`,\n // populated by `runEvalCampaign` and the adapters; falls back to\n // `outcome.raw.scenario_id` then `experimentId` when absent.\n const groups = new Map<string, Array<{ run: RunRecord; score: number }>>()\n for (const e of scoredEntries) {\n const sid = scenarioOf(e.run)\n const key = `${sid}::${e.run.seed}`\n const arr = groups.get(key) ?? []\n arr.push(e)\n groups.set(key, arr)\n }\n\n for (const [key, members] of groups.entries()) {\n cellsInspected++\n if (members.length < 2) {\n cellsSingleton++\n continue\n }\n for (let i = 0; i < members.length; i++) {\n for (let j = i + 1; j < members.length; j++) {\n const a = members[i]!\n const b = members[j]!\n if (a.run.candidateId === b.run.candidateId) continue\n const result = makePair(a, b, key.split('::')[0]!, minMargin)\n if (result.kind === 'admit') pairs.push(result.pair)\n else pairsBelowMargin++\n }\n }\n }\n } else if (strategy === 'paired-by-scenario') {\n // Group by scenarioId → average per (variantId, scenarioId) across seeds.\n const byScenarioVariant = new Map<\n string,\n Map<string, { run: RunRecord; sum: number; n: number }>\n >()\n for (const e of scoredEntries) {\n const sid = scenarioOf(e.run)\n let perScenario = byScenarioVariant.get(sid)\n if (!perScenario) {\n perScenario = new Map()\n byScenarioVariant.set(sid, perScenario)\n }\n const cur = perScenario.get(e.run.candidateId)\n if (cur) {\n cur.sum += e.score\n cur.n++\n } else perScenario.set(e.run.candidateId, { run: e.run, sum: e.score, n: 1 })\n }\n for (const [sid, perVariant] of byScenarioVariant.entries()) {\n cellsInspected++\n const arr = [...perVariant.entries()].map(([vid, agg]) => ({\n run: agg.run,\n score: agg.sum / agg.n,\n variantId: vid,\n }))\n if (arr.length < 2) {\n cellsSingleton++\n continue\n }\n for (let i = 0; i < arr.length; i++) {\n for (let j = i + 1; j < arr.length; j++) {\n const result = makePair(arr[i]!, arr[j]!, sid, minMargin)\n if (result.kind === 'admit') pairs.push(result.pair)\n else pairsBelowMargin++\n }\n }\n }\n } else {\n // top-vs-bottom: per scenario, top vs bottom only.\n const byScenario = new Map<string, Array<{ run: RunRecord; score: number }>>()\n for (const e of scoredEntries) {\n const sid = scenarioOf(e.run)\n const arr = byScenario.get(sid) ?? []\n arr.push(e)\n byScenario.set(sid, arr)\n }\n for (const [sid, arr] of byScenario.entries()) {\n cellsInspected++\n if (arr.length < 2) {\n cellsSingleton++\n continue\n }\n const sorted = [...arr].sort((a, b) => a.score - b.score)\n const top = sorted[sorted.length - 1]!\n const bot = sorted[0]!\n if (top.run.candidateId === bot.run.candidateId) {\n cellsSingleton++\n continue\n }\n const result = makePair(bot, top, sid, minMargin)\n if (result.kind === 'admit') pairs.push(result.pair)\n else pairsBelowMargin++\n }\n }\n\n return { pairs, cellsInspected, pairsBelowMargin, cellsSingleton, strategy }\n}\n\n/**\n * TRL-compatible export. TRL's `DPODataset` is `{ prompt, chosen, rejected }`\n * but the prompt isn't stored on the RunRecord — only its hash. The caller\n * passes a `promptOf(promptHash)` lookup that the TRL trainer can use.\n */\nexport function toTRLFormat(\n triples: PreferenceTriple[],\n promptOf: (hash: string) => string,\n): Array<{ prompt: string; chosen: string; rejected: string }> {\n return triples.map((t) => ({\n prompt: promptOf(t.meta.chosenPromptHash),\n chosen: t.meta.chosenPromptHash, // caller substitutes the model output via the runId map\n rejected: t.meta.rejectedPromptHash,\n }))\n}\n\n/**\n * Anthropic finetuning JSONL export — `{ system, user, assistant_chosen, assistant_rejected }`\n * shape. Same caveat as TRL: prompt + outputs are content the caller has\n * to map back from the run record / raw event log.\n */\nexport function toAnthropicFormat(\n triples: PreferenceTriple[],\n): Array<{ scenarioId: string; chosenRunId: string; rejectedRunId: string; margin: number }> {\n return triples.map((t) => ({\n scenarioId: t.scenarioId,\n chosenRunId: t.chosenRunId,\n rejectedRunId: t.rejectedRunId,\n margin: t.marginScore,\n }))\n}\n\n// ── Helpers ──────────────────────────────────────────────────────────────\n\nfunction makePair(\n a: { run: RunRecord; score: number },\n b: { run: RunRecord; score: number },\n scenarioId: string,\n minMargin: number,\n): { kind: 'admit'; pair: PreferenceTriple } | { kind: 'reject' } {\n const margin = Math.abs(a.score - b.score)\n if (margin < minMargin) return { kind: 'reject' }\n const [chosen, rejected] = a.score > b.score ? [a, b] : [b, a]\n return {\n kind: 'admit',\n pair: {\n scenarioId,\n chosenRunId: chosen.run.runId,\n rejectedRunId: rejected.run.runId,\n chosenVariantId: chosen.run.candidateId,\n rejectedVariantId: rejected.run.candidateId,\n marginScore: chosen.score - rejected.score,\n scores: { chosen: chosen.score, rejected: rejected.score },\n seed: chosen.run.seed === rejected.run.seed ? chosen.run.seed : undefined,\n meta: {\n chosenPromptHash: chosen.run.promptHash,\n rejectedPromptHash: rejected.run.promptHash,\n chosenConfigHash: chosen.run.configHash,\n rejectedConfigHash: rejected.run.configHash,\n chosenModel: chosen.run.model,\n rejectedModel: rejected.run.model,\n },\n },\n }\n}\n\n/**\n * Canonical scenario key for a RunRecord. Three-tier fallback:\n * 1. `run.scenarioId` — populated by `runEvalCampaign` and every adapter\n * 2. `run.outcome.raw.scenario_id` — string or numeric, when present\n * 3. `run.experimentId` — worst-case bucket\n */\nfunction scenarioOf(run: RunRecord): string {\n if (typeof run.scenarioId === 'string' && run.scenarioId.length > 0) return run.scenarioId\n const fromRaw = run.outcome.raw.scenario_id\n if (typeof fromRaw === 'number' && Number.isFinite(fromRaw)) return String(fromRaw)\n if (typeof fromRaw === 'string') return fromRaw\n return run.experimentId\n}\n","/**\n * Process reward extraction — step-level credit assignment from trace spans.\n *\n * RL on long-horizon agents needs *step-level* rewards, not run-level\n * ones. The classic credit-assignment problem (Sutton & Barto) requires\n * knowing which sub-decisions in a trajectory contributed to the\n * outcome. Modern systems (DeepSeek-R1, OpenAI o-series, Lightman et al.\n * \"Let's Verify Step by Step\" 2023) train *process reward models* (PRMs)\n * that score every step, then do RL with the PRM as the reward signal.\n *\n * This module extracts `StepReward[]` from trace spans — one per\n * meaningful step — and ships:\n *\n * 1. `extractStepRewards(store, runId, opts)` — span → step-reward\n * conversion using configurable per-span scorers (LLM judge over the\n * span output, deterministic checkers, or a learned PRM).\n * 2. `runwiseStepRewardSummary(stepRewards)` — aggregate the per-step\n * signal into a credit-assignment-aware run-level score.\n * 3. `prmTrainingPairs(stepRewards, options)` — produce the\n * `(prefix, suffix_chosen, suffix_rejected)` triples that PRM\n * training pipelines consume.\n *\n * What we ship: the *extraction* and *aggregation* infrastructure plus\n * the data shape PRM training expects. We do NOT ship the actual PRM\n * training (gradient descent over a transformer is out of scope for a\n * TS package). The interface is the contract; downstream consumers wire\n * their preferred trainer.\n *\n * Caveat the panel will land: this is descriptive credit assignment\n * (which steps correlate with outcome), not causal credit assignment\n * (which steps caused outcome). For causal claims you need\n * counterfactual rollouts or a learned dynamics model. Future work; the\n * descriptive version is what production PRM training actually uses.\n */\n\nimport type { Span } from '../trace/schema'\nimport type { TraceStore } from '../trace/store'\n\nexport interface StepReward {\n /** Trace span this reward attaches to. */\n spanId: string\n runId: string\n /** Index in the trajectory (0-based, in started-at order). */\n stepIndex: number\n /** Span kind (typically 'tool', 'llm', 'judge'). */\n kind: Span['kind']\n /** Span name — for the consumer's downstream filtering. */\n name: string\n /** Step-level reward in [0, 1]. */\n reward: number\n /**\n * Determinism class. Mirrors the verifiable-reward distinction:\n * deterministic = test/compile/schema check; probabilistic = LLM judge.\n */\n determinism: 'deterministic' | 'probabilistic'\n /** Optional rationale / evidence — the trainer typically discards. */\n rationale?: string\n /** Optional weight — how much this step contributes to credit assignment. */\n weight?: number\n}\n\nexport interface StepScorer {\n /** Span kinds this scorer applies to. */\n appliesTo: Span['kind'][]\n /** Returns null to skip the span; returns a `StepReward` shape (without index/runId/spanId, which are filled in). */\n score(span: Span): Promise<Omit<StepReward, 'spanId' | 'runId' | 'stepIndex'>> | null | undefined\n}\n\nexport interface ExtractStepRewardsOptions {\n /**\n * Ordered list of scorers. Each span runs through scorers in order;\n * the first non-null result wins. If no scorer applies, the span is\n * skipped (not all spans are training-worthy).\n */\n scorers: StepScorer[]\n /** Optional filter — return null to drop the span entirely before scoring. */\n preFilter?: (span: Span) => boolean\n}\n\nexport async function extractStepRewards(\n store: TraceStore,\n runId: string,\n opts: ExtractStepRewardsOptions,\n): Promise<StepReward[]> {\n const spans = await store.spans({ runId })\n const ordered = [...spans].sort((a, b) => a.startedAt - b.startedAt)\n const out: StepReward[] = []\n let idx = 0\n for (const span of ordered) {\n if (opts.preFilter && !opts.preFilter(span)) continue\n let scored: Awaited<ReturnType<StepScorer['score']>> = null\n for (const s of opts.scorers) {\n if (!s.appliesTo.includes(span.kind)) continue\n const r = await s.score(span)\n if (r) {\n scored = r\n break\n }\n }\n if (!scored) continue\n out.push({\n spanId: span.spanId,\n runId,\n stepIndex: idx++,\n kind: span.kind,\n name: span.name,\n reward: scored.reward,\n determinism: scored.determinism,\n rationale: scored.rationale,\n weight: scored.weight,\n })\n }\n return out\n}\n\nexport interface RunwiseStepSummary {\n runId: string\n totalSteps: number\n meanReward: number\n /** Sum-of-rewards (weighted by `weight ?? 1`). Use as the run-level proxy. */\n sumWeightedReward: number\n /** Fraction of steps where reward < 0.5 — proxy for \"where the policy was wrong.\" */\n failureFraction: number\n /** Maximum drop in reward between consecutive steps — diagnoses a step where things went sideways. */\n worstStepDelta: number\n worstStepIndex: number | null\n}\n\nexport function runwiseStepRewardSummary(stepRewards: StepReward[]): RunwiseStepSummary {\n if (stepRewards.length === 0) {\n return {\n runId: '',\n totalSteps: 0,\n meanReward: 0,\n sumWeightedReward: 0,\n failureFraction: 0,\n worstStepDelta: 0,\n worstStepIndex: null,\n }\n }\n const runId = stepRewards[0]!.runId\n let sumW = 0\n let sumWR = 0\n let failures = 0\n let worstDelta = 0\n let worstIdx: number | null = null\n let prev = stepRewards[0]!.reward\n for (let i = 0; i < stepRewards.length; i++) {\n const s = stepRewards[i]!\n const w = s.weight ?? 1\n sumW += w\n sumWR += w * s.reward\n if (s.reward < 0.5) failures++\n if (i > 0) {\n const delta = s.reward - prev\n if (delta < worstDelta) {\n worstDelta = delta\n worstIdx = i\n }\n prev = s.reward\n } else {\n prev = s.reward\n }\n }\n return {\n runId,\n totalSteps: stepRewards.length,\n meanReward: sumW === 0 ? 0 : sumWR / sumW,\n sumWeightedReward: sumWR,\n failureFraction: failures / stepRewards.length,\n worstStepDelta: worstDelta,\n worstStepIndex: worstIdx,\n }\n}\n\nexport interface PrmTrainingTriple {\n /** Prefix run-id (or composite key) — the trajectory up to step k-1. */\n prefixRunId: string\n prefixStepIndex: number\n /** The step that came next on a high-reward trajectory. */\n chosenSpanId: string\n chosenReward: number\n /** A step from a divergent low-reward trajectory at the same prefix length. */\n rejectedSpanId: string\n rejectedReward: number\n /** The prefix run came from this run; the rejected step came from `rejectedRunId`. */\n rejectedRunId: string\n marginScore: number\n}\n\n/**\n * Build PRM training triples. The shape: pair runs that share an early\n * prefix (same scenario, same first N steps) and diverge later — at the\n * point of divergence, the high-reward run's next step is `chosen`, the\n * low-reward run's next step is `rejected`. This is the canonical PRM\n * training data shape from Lightman et al. and DeepSeek-R1 process\n * supervision.\n *\n * Implementation note: we don't have a way to detect \"same prefix\" in\n * the general agent setting (token-level prefixes require hashing model\n * outputs). The current heuristic groups by `(scenarioId, prefixSpanName\n * sequence)` — runs are paired when their first K span names match. For\n * production use this should be replaced with a proper trajectory-prefix\n * hash; the heuristic is good enough for early-stage scaffolding.\n */\nexport function prmTrainingPairs(\n stepRewardsByRun: Map<string, StepReward[]>,\n opts: { minMargin?: number; minPrefixLength?: number } = {},\n): PrmTrainingTriple[] {\n const minMargin = opts.minMargin ?? 0.2\n const minPrefix = opts.minPrefixLength ?? 1\n const runs = [...stepRewardsByRun.entries()].map(([runId, steps]) => ({ runId, steps }))\n const triples: PrmTrainingTriple[] = []\n\n for (let i = 0; i < runs.length; i++) {\n for (let j = i + 1; j < runs.length; j++) {\n const a = runs[i]!\n const b = runs[j]!\n const minLen = Math.min(a.steps.length, b.steps.length)\n if (minLen < minPrefix + 1) continue\n\n // Find the first index where the trajectories diverge: either by\n // step structure (kind/name mismatch) OR by reward gap ≥ minMargin.\n // Names that match but rewards that differ ARE divergence — that's\n // the canonical PRM training case (same step structure, different\n // outcomes via state/context).\n let divergenceIdx = -1\n for (let k = 0; k < minLen; k++) {\n const sa = a.steps[k]!\n const sb = b.steps[k]!\n const structuralDivergence = sa.kind !== sb.kind || sa.name !== sb.name\n const rewardGap = Math.abs(sa.reward - sb.reward)\n if (structuralDivergence || rewardGap >= minMargin) {\n divergenceIdx = k\n break\n }\n }\n if (divergenceIdx < 0) continue\n if (divergenceIdx < minPrefix) continue\n\n const aNext = a.steps[divergenceIdx]!\n const bNext = b.steps[divergenceIdx]!\n const margin = Math.abs(aNext.reward - bNext.reward)\n if (margin < minMargin) continue\n\n const chosen = aNext.reward > bNext.reward ? aNext : bNext\n const rejected = aNext.reward > bNext.reward ? bNext : aNext\n const chosenRun = aNext.reward > bNext.reward ? a.runId : b.runId\n const rejectedRun = aNext.reward > bNext.reward ? b.runId : a.runId\n triples.push({\n prefixRunId: chosenRun,\n prefixStepIndex: divergenceIdx - 1,\n chosenSpanId: chosen.spanId,\n chosenReward: chosen.reward,\n rejectedSpanId: rejected.spanId,\n rejectedReward: rejected.reward,\n rejectedRunId: rejectedRun,\n marginScore: chosen.reward - rejected.reward,\n })\n }\n }\n return triples\n}\n","/**\n * `runRLCampaign` — top-level orchestrator that runs the matrix and\n * produces every RL-ready artifact in one call.\n *\n * Wires:\n * 1. `runEvalCampaign` for the matrix run (capture, integrity, hooks)\n * 2. `extractVerifiableReward` over each run, separating deterministic\n * from probabilistic reward sources for the trainer\n * 3. `extractPreferences` to produce DPO/PPO/KTO triples\n * 4. `evaluateInterimReleaseConfidence` over paired deltas (anytime-valid)\n * 5. `rubricPredictiveValidity` against an outcome store, when provided\n * 6. `detectRewardHacking` as a standing hygiene check\n * 7. Trainer-format export rows ready for prime-rl / TRL / verl\n *\n * The output `RLCampaignResult` is a single, audit-ready artifact: every\n * stage's output is in there. The consumer's downstream fits in a single\n * line: pass `result.preferences` to their DPO trainer, `result.grpoRows`\n * to GRPO, `result.runs` plus `result.rewardSignals` to a custom RL loop.\n */\n\nimport {\n type EvalCampaignOptions,\n type EvalCampaignResult,\n runEvalCampaign,\n} from '../eval-campaign'\nimport type { OutcomeStore } from '../meta-eval/outcome-store'\nimport {\n type RubricPredictiveValidityReport,\n rubricPredictiveValidity,\n} from '../meta-eval/rubric-predictive-validity'\nimport type { RunRecord } from '../run-record'\nimport { evaluateInterimReleaseConfidence, type InterimReleaseConfidence } from '../sequential'\nimport {\n type DpoExportRow,\n type DpoLookups,\n type GrpoExportRow,\n type GrpoLookups,\n type SftExportRow,\n type SftLookups,\n toDpoRows,\n toGrpoRows,\n toSftRows,\n} from './exporters'\nimport {\n type ExtractPreferencesOptions,\n extractPreferences,\n type PreferenceExtractionReport,\n} from './preferences'\nimport { detectRewardHacking, type RewardHackingReport } from './reward-hacking'\nimport {\n extractVerifiableRewardsFromRecords,\n type VerifiableReward,\n type VerifiableRewardExtractionOptions,\n} from './verifiable-reward'\n\nexport interface RunRLCampaignOptions<V> extends EvalCampaignOptions<V> {\n /** Preference-extraction options. Default uses paired-by-scenario-and-seed with min-margin 0.05. */\n preferences?: ExtractPreferencesOptions\n /** Verifiable-reward extraction options. */\n verifiableReward?: VerifiableRewardExtractionOptions\n /** Outcome store + metric names — when supplied, runs `rubricPredictiveValidity` post-campaign. */\n outcomeStore?: OutcomeStore\n outcomeMetrics?: string[]\n /** Anytime-valid sequential evaluation options. */\n sequential?: { alpha?: number; bound?: number; rope?: { low: number; high: number } }\n /** Trainer-format export lookups. When provided, the orchestrator builds the corresponding rows. */\n trainerExport?: {\n dpo?: DpoLookups\n grpo?: GrpoLookups\n sft?: SftLookups\n }\n}\n\nexport interface RLCampaignResult<V> {\n campaign: EvalCampaignResult\n /** Per-run verifiable reward (deterministic when available, probabilistic fallback otherwise). */\n rewardSignals: Array<{ runId: string; reward: VerifiableReward | null }>\n /** Preference extraction report. */\n preferences: PreferenceExtractionReport\n /** Anytime-valid interim verdict over the paired deltas (vs comparator). */\n interimConfidence: InterimReleaseConfidence | null\n /** Standing reward-hacking hygiene check. */\n rewardHacking: RewardHackingReport\n /** Predictive validity, when an outcome store was supplied. */\n predictiveValidity: RubricPredictiveValidityReport | null\n /** Trainer-export rows, populated only for the formats the caller requested via `trainerExport`. */\n trainerRows: {\n dpo?: DpoExportRow[]\n grpo?: GrpoExportRow[]\n sft?: SftExportRow[]\n }\n /**\n * One-line top-level summary the consumer can log.\n */\n summary: string\n /**\n * Convenience type-tag — consumers can branch on `result.kind`.\n */\n kind: 'agent-eval-rl-campaign'\n unusedVariant?: V\n}\n\nexport async function runRLCampaign<V>(\n opts: RunRLCampaignOptions<V>,\n): Promise<RLCampaignResult<V>> {\n // ── 1. Run the matrix ──────────────────────────────────────────────\n const campaign = await runEvalCampaign(opts)\n\n // ── 2. Extract reward signals (deterministic-first) ────────────────\n const rewardSignals = extractVerifiableRewardsFromRecords(\n campaign.runs,\n opts.verifiableReward ?? {},\n )\n\n // ── 3. Extract preference triples ──────────────────────────────────\n const preferences = extractPreferences(campaign.runs, {\n strategy: opts.preferences?.strategy ?? 'paired-by-scenario-and-seed',\n minMargin: opts.preferences?.minMargin ?? 0.05,\n splitTag: opts.preferences?.splitTag ?? opts.splitTag ?? 'holdout',\n rewardOf: opts.preferences?.rewardOf,\n })\n\n // ── 4. Sequential / anytime-valid interim verdict ──────────────────\n let interimConfidence: InterimReleaseConfidence | null = null\n if (opts.report?.comparator) {\n const comparator = opts.report.comparator\n const deltaSeries = collectPairedDeltaSeries(campaign.runs, comparator)\n if (deltaSeries.some((s) => s.deltas.length > 0)) {\n interimConfidence = evaluateInterimReleaseConfidence({\n deltaSeries,\n alpha: opts.sequential?.alpha,\n bound: opts.sequential?.bound,\n rope: opts.sequential?.rope ?? opts.report?.rope,\n })\n }\n }\n\n // ── 5. Standing reward-hacking hygiene ─────────────────────────────\n const rewardHacking = detectRewardHacking({\n runs: campaign.runs,\n verifiableRewardOptions: opts.verifiableReward,\n })\n\n // ── 6. Predictive validity (when outcomes are supplied) ────────────\n let predictiveValidity: RubricPredictiveValidityReport | null = null\n if (opts.outcomeStore && opts.outcomeMetrics && opts.outcomeMetrics.length > 0) {\n predictiveValidity = await rubricPredictiveValidity({\n runs: campaign.runs,\n outcomes: opts.outcomeStore,\n outcomeMetrics: opts.outcomeMetrics,\n })\n }\n\n // ── 7. Trainer-format export ───────────────────────────────────────\n const trainerRows: RLCampaignResult<V>['trainerRows'] = {}\n if (opts.trainerExport?.dpo) {\n trainerRows.dpo = await toDpoRows(preferences.pairs, opts.trainerExport.dpo)\n }\n if (opts.trainerExport?.grpo) {\n trainerRows.grpo = await toGrpoRows(campaign.runs, opts.trainerExport.grpo)\n }\n if (opts.trainerExport?.sft) {\n trainerRows.sft = await toSftRows(campaign.runs, opts.trainerExport.sft)\n }\n\n const summary = buildSummary({\n campaign,\n preferences,\n interimConfidence,\n rewardHacking,\n predictiveValidity,\n })\n\n return {\n campaign,\n rewardSignals,\n preferences,\n interimConfidence,\n rewardHacking,\n predictiveValidity,\n trainerRows,\n summary,\n kind: 'agent-eval-rl-campaign',\n }\n}\n\n// ── Helpers ──────────────────────────────────────────────────────────────\n\nfunction collectPairedDeltaSeries(\n runs: RunRecord[],\n comparator: string,\n): Array<{ candidateId: string; deltas: number[] }> {\n // Pair on (scenarioId, seed). For each candidate that isn't the comparator,\n // compute candidate.score - comparator.score on matching cells.\n const baseline = new Map<string, number>()\n for (const r of runs) {\n if (r.candidateId !== comparator) continue\n const sid = r.scenarioId ?? r.experimentId\n const score = r.outcome.holdoutScore ?? r.outcome.searchScore\n if (typeof score !== 'number' || !Number.isFinite(score)) continue\n baseline.set(`${sid}::${r.seed}`, score)\n }\n const byCandidate = new Map<string, number[]>()\n for (const r of runs) {\n if (r.candidateId === comparator) continue\n const sid = r.scenarioId ?? r.experimentId\n const score = r.outcome.holdoutScore ?? r.outcome.searchScore\n if (typeof score !== 'number' || !Number.isFinite(score)) continue\n const baseScore = baseline.get(`${sid}::${r.seed}`)\n if (typeof baseScore !== 'number') continue\n const arr = byCandidate.get(r.candidateId) ?? []\n arr.push(score - baseScore)\n byCandidate.set(r.candidateId, arr)\n }\n return [...byCandidate.entries()].map(([candidateId, deltas]) => ({ candidateId, deltas }))\n}\n\nfunction buildSummary(args: {\n campaign: EvalCampaignResult\n preferences: PreferenceExtractionReport\n interimConfidence: InterimReleaseConfidence | null\n rewardHacking: RewardHackingReport\n predictiveValidity: RubricPredictiveValidityReport | null\n}): string {\n const c = args.campaign\n const lines = [\n `${c.campaignId}: ${c.runs.length} successful runs / ${c.failedRuns.length} failed (fingerprint ${c.campaignFingerprint.slice(0, 12)}…)`,\n `preferences: ${args.preferences.pairs.length} (${args.preferences.strategy}, ${args.preferences.pairsBelowMargin} below margin)`,\n ]\n if (args.interimConfidence) {\n lines.push(\n `sequential verdict: ${args.interimConfidence.recommendation.decision}` +\n (args.interimConfidence.recommendation.candidateId\n ? ` ${args.interimConfidence.recommendation.candidateId}`\n : ''),\n )\n }\n lines.push(\n `reward-hacking: ${args.rewardHacking.verdict} (${args.rewardHacking.findings.length} signals checked)`,\n )\n if (args.predictiveValidity) {\n const top = args.predictiveValidity.ranked[0]\n lines.push(\n `top-rubric: ${top?.rubric ?? 'none'} ρ=${(top?.spearman ?? 0).toFixed(2)} (${top?.verdict ?? 'no data'})`,\n )\n }\n return lines.join(' | ')\n}\n\n// Re-export `runEvalCampaign` so consumers can pick the lower-level\n// primitive without flipping import paths.\nexport { runEvalCampaign } from '../eval-campaign'\n","/**\n * Adapters: convert measurement outputs into the canonical `RunRecord[]`\n * artifact that `replayCache`, `pairedEvalueSequence`, and\n * `rubricPredictiveValidity` consume. Two sources:\n * - `campaignToRunRecords` — the campaign substrate's per-cell results\n * (the modern path: `runCampaign` / `runImprovementLoop` → records).\n * - `verificationReportToRunRecord` — a `MultiLayerVerifier` report.\n *\n * Adapters are thin and explicit — every mandatory `RunRecord` field comes\n * from a caller-supplied context (`commitSha`, `model`, `promptHash`,\n * `configHash`) plus the cell's runtime data. The validator still rejects\n * bare-alias model strings — the caller snapshot-pins.\n */\n\nimport type { CampaignResult } from '../campaign'\nimport type { LayerResult, VerificationReport } from '../multi-layer-verifier'\nimport type { RunRecord, RunSplitTag } from '../run-record'\n\nexport interface AdapterContext {\n /** Logical experiment id — typically the campaign or sweep identifier. */\n experimentId: string\n /** Snapshot model id (e.g. `claude-sonnet-4-6@2025-04-15`). */\n model: string\n /** Git SHA the harness was run from. */\n commitSha: string\n /** Hash of the effective prompt sent to the model. */\n promptHash: string\n /** Hash of the effective config (model, temperature, tools, judges, splits). */\n configHash: string\n /** Default split tag. Default `'search'`. */\n splitTag?: RunSplitTag\n /** Default cost in USD when the source doesn't record one. Default `0`. */\n defaultCostUsd?: number\n}\n\n/**\n * Convert a `CampaignResult` into canonical `RunRecord[]` — one record per\n * scored cell. The cell's mean judge composite becomes the split score; every\n * judge dimension is carried through to `outcome.raw`. A cell that errored\n * becomes a record with `failureMode: 'cell_error'` (kept, not dropped — an\n * unscored cell is signal). `candidateId` identifies the measured surface\n * (defaults to the campaign manifest hash).\n */\nexport function campaignToRunRecords(\n campaign: CampaignResult,\n ctx: AdapterContext & { candidateId?: string },\n): RunRecord[] {\n const splitTag = ctx.splitTag ?? 'search'\n const candidateId = ctx.candidateId ?? campaign.manifestHash\n return campaign.cells.map((cell) => {\n const composites = Object.values(cell.judgeScores).map((s) => s.composite)\n const score =\n composites.length > 0 ? composites.reduce((a, b) => a + b, 0) / composites.length : 0\n const raw: Record<string, number> = { rep: cell.rep, duration_ms: cell.durationMs }\n for (const judge of Object.values(cell.judgeScores)) {\n for (const [dim, value] of Object.entries(judge.dimensions)) {\n if (Number.isFinite(value)) raw[`dim.${dim}`] = value\n }\n }\n if (typeof cell.generation === 'number') raw.generation = cell.generation\n const outcome: RunRecord['outcome'] = { raw }\n if (splitTag === 'holdout') outcome.holdoutScore = score\n else outcome.searchScore = score\n return {\n runId: cell.cellId,\n experimentId: ctx.experimentId,\n candidateId,\n seed: cell.seed,\n model: ctx.model,\n promptHash: ctx.promptHash,\n configHash: ctx.configHash,\n commitSha: ctx.commitSha,\n wallMs: cell.durationMs,\n costUsd: Number.isFinite(cell.costUsd) ? cell.costUsd : (ctx.defaultCostUsd ?? 0),\n tokenUsage: { input: 0, output: 0 },\n outcome,\n failureMode: cell.error ? 'cell_error' : undefined,\n splitTag,\n scenarioId: cell.scenarioId,\n }\n })\n}\n\n/**\n * Convert a `MultiLayerVerifier` `VerificationReport` into a `RunRecord`.\n * `outcome.searchScore` (or `holdoutScore`) is `report.blendedScore`;\n * `outcome.raw` carries every layer's score + a pass indicator; `failureMode`\n * is the first failing layer's reason.\n */\nexport function verificationReportToRunRecord(\n report: VerificationReport,\n ctx: AdapterContext & { candidateId: string; scenarioId?: string },\n opts: { runId?: string } = {},\n): RunRecord {\n const splitTag = ctx.splitTag ?? 'search'\n const runId = opts.runId ?? `run-${ctx.candidateId}-${ctx.experimentId}-${report.startedAt}`\n\n const raw: Record<string, number> = {\n pass_count: report.passCount,\n fail_count: report.failCount,\n error_count: report.errorCount,\n skipped_count: report.skippedCount,\n duration_ms: report.durationMs,\n blended_score: report.blendedScore,\n }\n for (const layer of report.layers) {\n if (typeof layer.score === 'number') raw[`layer.${layer.layer}`] = layer.score\n raw[`layer_${layer.layer}_pass`] = layer.status === 'pass' ? 1 : 0\n if (layer.diagnostics) {\n for (const [k, v] of Object.entries(layer.diagnostics)) {\n if (typeof v === 'number' && Number.isFinite(v)) raw[`layer.${layer.layer}.${k}`] = v\n }\n }\n }\n\n const firstFail = report.layers.find((l) => l.status === 'fail' || l.status === 'error')\n const outcome: RunRecord['outcome'] = { raw }\n if (splitTag === 'holdout') outcome.holdoutScore = report.blendedScore\n else outcome.searchScore = report.blendedScore\n\n return {\n runId,\n experimentId: ctx.experimentId,\n candidateId: ctx.candidateId,\n seed: 0,\n model: ctx.model,\n promptHash: ctx.promptHash,\n configHash: ctx.configHash,\n commitSha: ctx.commitSha,\n wallMs: report.durationMs,\n costUsd: ctx.defaultCostUsd ?? 0,\n tokenUsage: { input: 0, output: 0 },\n outcome,\n failureMode: firstFail ? failureModeFromLayer(firstFail) : undefined,\n splitTag,\n scenarioId: ctx.scenarioId,\n }\n}\n\nfunction failureModeFromLayer(layer: LayerResult): string {\n if (layer.status === 'error') return `layer_${layer.layer}_error`\n if (layer.status === 'fail') return `layer_${layer.layer}_fail`\n if (layer.status === 'timeout') return `layer_${layer.layer}_timeout`\n return `layer_${layer.layer}_${layer.status}`\n}\n","/**\n * Simulator fidelity — score a user SIMULATOR's realism against real-user\n * trace distributions.\n *\n * Synthetic-persona evals (`PersonaConfig`-driven canonical evals, fuzz\n * user-simulator objectives) stand in for real users in most of the numbers\n * we publish. The standing threat is the Sim2Real gap: a simulator that is\n * distributionally unlike production creates \"easy mode\" and silently\n * inflates every score built on it. This module measures that gap from the\n * SAME artifact both sides already produce — `RunRecord`s — so no new\n * capture pipeline is needed:\n *\n * - `simFidelityReport` — per-feature Jensen-Shannon divergence between\n * simulated and production record distributions, collapsed into a\n * fidelity coefficient in [0,1].\n * - `easyModeCheck` — the headline academic failure mode (sim inflates\n * pass-rate over production) as its own named artifact.\n *\n * Every synthetic-persona eval result should publish its fidelity\n * coefficient alongside the score — a number from an unrepresentative\n * simulator is an unlabeled estimate. Wire-in points:\n *\n * - canonical persona evals: pass the campaign's `RunRecord`s as\n * `simulated` and intake-adapter output (`contract/intake`: OTel spans,\n * feedback tables, coding-agent sessions) as `production`\n * - the fuzz user-sim objective: use `1 - report.fidelity` as a realism\n * penalty when searching over generated personas\n * - the durable corpus (`./corpus`): both sides read straight from\n * `readCorpus` — tag sim vs production by `experimentId`\n */\n\nimport { ValidationError } from '../errors'\nimport type { RunRecord } from '../run-record'\nimport type { FailureClass } from '../trace/schema'\nimport type { CorpusRecord } from './corpus'\n\n/** Extracts a flat behavioral feature map from one record. `string` values\n * are categorical, `number` values are quantile-bucketed over the union of\n * both sides, `null` means the feature is absent on this record and is\n * counted explicitly as its own category (never silently dropped). */\nexport type BehaviorFeatures = (record: RunRecord) => Record<string, string | number | null>\n\n/** Reserved histogram category for `null` feature values. A capture-rate\n * difference (one side instruments a signal, the other does not) registers\n * as divergence by design: a simulator that produces no tool traces is not\n * representative of production that does. */\nexport const ABSENT_CATEGORY = '(absent)'\n\n/** Minimum non-null observations PER SIDE for a feature to enter the\n * fidelity mean. Below this the JSD estimate is sampling noise. */\nexport const DEFAULT_MIN_N_PER_FEATURE = 20\n\n/** Quantile buckets used to discretize numeric features. Quartiles balance\n * resolution against per-bucket sample size at the default minN. */\nexport const DEFAULT_QUANTILE_BUCKETS = 4\n\n/** Fidelity at or above this → 'representative'; below → 'skewed'.\n * 1 − 0.8 = mean JSD 0.2 ≈ distributions that mostly overlap with one\n * clearly shifted mode — the point where per-feature shifts start changing\n * which failure classes an eval can even observe. */\nexport const REPRESENTATIVE_MIN_FIDELITY = 0.8\n\nconst TOP_SHIFT_COUNT = 5\n\n/**\n * Default feature set — ONLY fields verified present on both simulated and\n * production records:\n *\n * - `score`, `wall_ms`, `output_tokens` — mandatory per the `RunRecord`\n * validator (non-finite values read as absent rather than poisoning a\n * bucket).\n * - `failure_class` — optional taxonomy field; absent counted explicitly.\n * - `turn_count`, `tool_errors`, `tool_error_recovery` — derived from the\n * `outcome.raw` counters the intake adapters and eval harnesses write\n * (`turns_completed`, `assistant_messages`, `tool_errors`,\n * `turns_aborted`); absent on records whose producer did not capture\n * them, counted explicitly.\n * - `completion_length` — from the optional `CorpusRecord` trajectory\n * text; the message-length proxy when records come from the corpus.\n *\n * `RunRecord` carries event COUNTS, not event ordering, so\n * `tool_error_recovery` is a counts-only derivation: errors occurred and the\n * run still completed cleanly ('recovered') vs aborted or classified as a\n * failure ('unrecovered') — not a literal error→retry sequence check.\n */\nexport const defaultBehaviorFeatures: BehaviorFeatures = (record) => {\n const raw: Record<string, number> = record.outcome?.raw ?? {}\n const toolErrors = finiteOrNull(raw.tool_errors)\n const turnsAborted = finiteOrNull(raw.turns_aborted)\n const completion = (record as CorpusRecord).completion\n return {\n score: finiteOrNull(record.outcome?.holdoutScore) ?? finiteOrNull(record.outcome?.searchScore),\n failure_class: record.failureClass ?? null,\n wall_ms: finiteOrNull(record.wallMs),\n output_tokens: finiteOrNull(record.tokenUsage?.output),\n turn_count: finiteOrNull(raw.turns_completed) ?? finiteOrNull(raw.assistant_messages),\n tool_errors: toolErrors,\n tool_error_recovery: toolErrorRecovery(toolErrors, turnsAborted, record.failureClass),\n completion_length: typeof completion === 'string' ? completion.length : null,\n }\n}\n\nfunction toolErrorRecovery(\n toolErrors: number | null,\n turnsAborted: number | null,\n failureClass: FailureClass | undefined,\n): string | null {\n if (toolErrors === null) return null\n if (toolErrors === 0) return 'no-tool-errors'\n const failed =\n (turnsAborted ?? 0) > 0 || (failureClass !== undefined && failureClass !== 'success')\n return failed ? 'unrecovered' : 'recovered'\n}\n\nfunction finiteOrNull(value: unknown): number | null {\n return typeof value === 'number' && Number.isFinite(value) ? value : null\n}\n\n// ── Divergence core ──────────────────────────────────────────────────\n\n/**\n * Jensen-Shannon divergence between two categorical histograms (raw counts;\n * normalized internally). Log base 2 → bounded [0,1]: 0 = identical\n * distributions, 1 = disjoint support. Symmetric, defined even where the\n * supports differ — exactly the regime sim-vs-production comparison lives in.\n * Throws on zero-mass or negative/non-finite counts: an empty histogram has\n * no distribution and a silent 0 would read as \"perfectly representative\".\n */\nexport function jsDivergence(p: Record<string, number>, q: Record<string, number>): number {\n const keys = new Set([...Object.keys(p), ...Object.keys(q)])\n if (keys.size === 0) {\n throw new ValidationError('jsDivergence: both histograms are empty')\n }\n let pSum = 0\n let qSum = 0\n for (const key of keys) {\n const pv = p[key] ?? 0\n const qv = q[key] ?? 0\n if (!Number.isFinite(pv) || !Number.isFinite(qv) || pv < 0 || qv < 0) {\n throw new ValidationError(`jsDivergence: negative or non-finite count for category \"${key}\"`)\n }\n pSum += pv\n qSum += qv\n }\n if (pSum === 0 || qSum === 0) {\n throw new ValidationError('jsDivergence: a histogram with zero total mass has no distribution')\n }\n let divergence = 0\n for (const key of keys) {\n const pp = (p[key] ?? 0) / pSum\n const qp = (q[key] ?? 0) / qSum\n const m = (pp + qp) / 2\n if (pp > 0) divergence += 0.5 * pp * Math.log2(pp / m)\n if (qp > 0) divergence += 0.5 * qp * Math.log2(qp / m)\n }\n // float error can land epsilon outside [0,1]\n return Math.min(1, Math.max(0, divergence))\n}\n\n/**\n * Deterministic quantile edges over a value set (the UNION of both sides, so\n * sim and production land in the same buckets). Linear interpolation between\n * order statistics; duplicate edges from heavy ties collapse into fewer,\n * wider buckets. Returns `bucketCount - 1` edges before deduplication.\n */\nexport function quantileEdges(values: number[], bucketCount = DEFAULT_QUANTILE_BUCKETS): number[] {\n if (values.length === 0) {\n throw new ValidationError('quantileEdges: requires at least one value')\n }\n if (!Number.isInteger(bucketCount) || bucketCount < 2) {\n throw new ValidationError(\n `quantileEdges: bucketCount must be an integer >= 2, got ${bucketCount}`,\n )\n }\n const sorted = [...values].sort((a, b) => a - b)\n const edges: number[] = []\n for (let k = 1; k < bucketCount; k++) {\n const pos = (k / bucketCount) * (sorted.length - 1)\n const lo = sorted[Math.floor(pos)]!\n const hi = sorted[Math.ceil(pos)]!\n edges.push(lo + (pos - Math.floor(pos)) * (hi - lo))\n }\n return [...new Set(edges)]\n}\n\n/** Stable half-open bucket label for a value against quantile edges:\n * `[-inf,e0)`, `[e0,e1)`, …, `[eLast,+inf)`. */\nexport function bucketLabel(value: number, edges: number[]): string {\n let i = 0\n while (i < edges.length && value >= edges[i]!) i++\n const lo = i === 0 ? '-inf' : String(edges[i - 1]!)\n const hi = i === edges.length ? '+inf' : String(edges[i]!)\n return `[${lo},${hi})`\n}\n\n// ── Fidelity report ──────────────────────────────────────────────────\n\nexport interface FeatureShift {\n /** Category label (a string value, a numeric bucket, or `ABSENT_CATEGORY`). */\n value: string\n /** Probability of this category among ALL simulated records (nulls included\n * via `ABSENT_CATEGORY`, so each side's shifts sum to 1). */\n pSim: number\n /** Probability among ALL production records. */\n pProd: number\n}\n\nexport interface FeatureDivergence {\n feature: string\n /** Jensen-Shannon divergence in [0,1] for this feature. */\n divergence: number\n /** Largest |pSim − pProd| categories, descending — where the sim deviates. */\n topShifts: FeatureShift[]\n /** Non-null observations on the simulated side. */\n nSim: number\n /** Non-null observations on the production side. */\n nProd: number\n}\n\nexport type FidelityVerdict = 'representative' | 'skewed' | 'insufficient-data'\n\nexport interface FidelityReport {\n perDimension: FeatureDivergence[]\n /** 1 − mean divergence over features with sufficient data. NaN when the\n * verdict is 'insufficient-data' — a 0 would read as \"maximally skewed\"\n * and silently poison downstream aggregation; check `verdict` first. */\n fidelity: number\n /** Features excluded because either side had fewer than `minNPerFeature`\n * non-null observations. Named, never silently dropped. */\n insufficientData: string[]\n /** 'representative' when fidelity >= REPRESENTATIVE_MIN_FIDELITY (0.8),\n * 'skewed' below, 'insufficient-data' when no feature met minN. */\n verdict: FidelityVerdict\n}\n\nexport interface SimFidelityOptions {\n /** Feature extractor. Defaults to `defaultBehaviorFeatures`. */\n features?: BehaviorFeatures\n /** Minimum non-null observations per side per feature. Default 20. */\n minNPerFeature?: number\n}\n\n/**\n * Compare a simulator's RunRecords against production RunRecords, feature by\n * feature. Numeric features are bucketed by deterministic quantiles of the\n * union; nulls count as an explicit `ABSENT_CATEGORY`. Throws on empty\n * inputs — \"no records\" is a wiring error, not a distribution.\n */\nexport function simFidelityReport(\n simulated: RunRecord[],\n production: RunRecord[],\n opts: SimFidelityOptions = {},\n): FidelityReport {\n if (simulated.length === 0) {\n throw new ValidationError('simFidelityReport: simulated records are empty')\n }\n if (production.length === 0) {\n throw new ValidationError('simFidelityReport: production records are empty')\n }\n const extract = opts.features ?? defaultBehaviorFeatures\n const minN = opts.minNPerFeature ?? DEFAULT_MIN_N_PER_FEATURE\n\n const simMaps = simulated.map(extract)\n const prodMaps = production.map(extract)\n\n // union of feature names in first-seen order — extractors may emit\n // different keys per record (e.g. domain-conditional features)\n const featureNames: string[] = []\n const seen = new Set<string>()\n for (const map of [...simMaps, ...prodMaps]) {\n for (const name of Object.keys(map)) {\n if (!seen.has(name)) {\n seen.add(name)\n featureNames.push(name)\n }\n }\n }\n\n const perDimension: FeatureDivergence[] = []\n const insufficientData: string[] = []\n\n for (const feature of featureNames) {\n const simVals = simMaps.map((m) => m[feature] ?? null)\n const prodVals = prodMaps.map((m) => m[feature] ?? null)\n const nSim = simVals.filter((v) => v !== null).length\n const nProd = prodVals.filter((v) => v !== null).length\n if (nSim < minN || nProd < minN) {\n insufficientData.push(feature)\n continue\n }\n const { sim, prod } = histograms(feature, simVals, prodVals)\n perDimension.push({\n feature,\n divergence: jsDivergence(sim, prod),\n topShifts: topShifts(sim, simVals.length, prod, prodVals.length),\n nSim,\n nProd,\n })\n }\n\n if (perDimension.length === 0) {\n return { perDimension, fidelity: Number.NaN, insufficientData, verdict: 'insufficient-data' }\n }\n const fidelity = 1 - perDimension.reduce((sum, d) => sum + d.divergence, 0) / perDimension.length\n return {\n perDimension,\n fidelity,\n insufficientData,\n verdict: fidelity >= REPRESENTATIVE_MIN_FIDELITY ? 'representative' : 'skewed',\n }\n}\n\ntype FeatureValue = string | number | null\n\nfunction histograms(\n feature: string,\n simVals: FeatureValue[],\n prodVals: FeatureValue[],\n): { sim: Record<string, number>; prod: Record<string, number> } {\n const kinds = new Set<string>()\n for (const v of [...simVals, ...prodVals]) {\n if (v !== null) kinds.add(typeof v)\n }\n if (kinds.size > 1) {\n throw new ValidationError(\n `simFidelityReport: feature \"${feature}\" mixes string and number values — an extractor must return one kind per feature`,\n )\n }\n let toCategory: (v: string | number) => string\n if (kinds.has('number')) {\n const union: number[] = []\n for (const v of [...simVals, ...prodVals]) {\n if (v !== null) union.push(v as number)\n }\n const edges = quantileEdges(union)\n toCategory = (v) => bucketLabel(v as number, edges)\n } else {\n toCategory = (v) => v as string\n }\n const count = (vals: FeatureValue[]): Record<string, number> => {\n const hist: Record<string, number> = {}\n for (const v of vals) {\n const key = v === null ? ABSENT_CATEGORY : toCategory(v)\n hist[key] = (hist[key] ?? 0) + 1\n }\n return hist\n }\n return { sim: count(simVals), prod: count(prodVals) }\n}\n\nfunction topShifts(\n sim: Record<string, number>,\n simTotal: number,\n prod: Record<string, number>,\n prodTotal: number,\n): FeatureShift[] {\n const keys = [...new Set([...Object.keys(sim), ...Object.keys(prod)])]\n const shifts = keys.map((value) => ({\n value,\n pSim: (sim[value] ?? 0) / simTotal,\n pProd: (prod[value] ?? 0) / prodTotal,\n }))\n shifts.sort((a, b) => {\n const delta = Math.abs(b.pSim - b.pProd) - Math.abs(a.pSim - a.pProd)\n return delta !== 0 ? delta : a.value.localeCompare(b.value)\n })\n return shifts.slice(0, TOP_SHIFT_COUNT)\n}\n\n// ── Easy-mode check ──────────────────────────────────────────────────\n\nexport interface EasyModeOptions {\n /** A run passes when its score (holdout, else search) >= this. Default 0.5\n * — matches the pass-threshold convention across the rl/ primitives. */\n passThreshold?: number\n /** Pass-rate gap above which the sim is flagged inflated. Default 0.1 —\n * a 10-point inflation is enough to flip most promotion gates. */\n inflationTolerance?: number\n}\n\nexport interface EasyModeReport {\n simPassRate: number\n prodPassRate: number\n /** simPassRate − prodPassRate. Positive = the simulator is easier than reality. */\n gap: number\n /** True when gap > inflationTolerance: numbers measured against this\n * simulator overstate production performance. */\n inflated: boolean\n}\n\n/**\n * The headline simulator failure mode as its own named artifact: a simulator\n * that creates \"easy mode\" inflates pass-rate relative to production, and\n * every score measured against it overstates reality. Throws on empty inputs\n * and on records carrying neither score — a silently-skipped record would\n * bias the very rate this check exists to keep honest.\n */\nexport function easyModeCheck(\n simulated: RunRecord[],\n production: RunRecord[],\n opts: EasyModeOptions = {},\n): EasyModeReport {\n if (simulated.length === 0) {\n throw new ValidationError('easyModeCheck: simulated records are empty')\n }\n if (production.length === 0) {\n throw new ValidationError('easyModeCheck: production records are empty')\n }\n const threshold = opts.passThreshold ?? 0.5\n const tolerance = opts.inflationTolerance ?? 0.1\n const passRate = (records: RunRecord[], side: string): number => {\n let passes = 0\n for (const r of records) {\n const score = finiteOrNull(r.outcome?.holdoutScore) ?? finiteOrNull(r.outcome?.searchScore)\n if (score === null) {\n throw new ValidationError(\n `easyModeCheck: ${side} run \"${r.runId}\" carries neither holdoutScore nor searchScore`,\n )\n }\n if (score >= threshold) passes++\n }\n return passes / records.length\n }\n const simPassRate = passRate(simulated, 'simulated')\n const prodPassRate = passRate(production, 'production')\n const gap = simPassRate - prodPassRate\n return { simPassRate, prodPassRate, gap, inflated: gap > tolerance }\n}\n","/**\n * Bradley-Terry / Elo tournament evaluation.\n *\n * For multi-candidate sweeps, comparing every candidate's score against\n * a fixed comparator wastes information — the comparator becomes a high-\n * variance reference and rank flips between near-tied middle-rank\n * candidates are dominated by noise. Pairwise tournaments fix this:\n * every (i, j) pair contributes a comparison to a Bradley-Terry MLE that\n * estimates each candidate's strength on a unified scale.\n *\n * For online updating (rolling campaigns where new candidates arrive\n * over time), we also ship classical Elo with configurable K-factor.\n *\n * References:\n * - Bradley, R. A., Terry, M. E. (1952). Rank analysis of incomplete\n * block designs. Biometrika, 39(3/4), 324–345.\n * - Hunter, D. R. (2004). MM algorithms for generalized Bradley-Terry\n * models. Annals of Statistics, 32(1), 384–406. (The MLE algorithm\n * used here.)\n * - Elo, A. E. (1978). The Rating of Chess Players, Past and Present.\n *\n * This is a useful primitive because most LLM-eval communities (Chatbot\n * Arena, AlpacaEval, ELO-style ablation) have converged on pairwise\n * tournament eval as the most sample-efficient and most rank-stable\n * method when you have many candidates.\n */\n\nexport interface PairwiseOutcome {\n /** Winner candidate id. */\n winner: string\n /** Loser candidate id. */\n loser: string\n /**\n * Optional draw flag. When true, both candidates get half-credit\n * (Bradley-Terry handles draws as half-wins for each side).\n */\n draw?: boolean\n /**\n * Optional weight — useful if some pairwise comparisons are stronger\n * signals than others (e.g. a paired test with a wider score gap is\n * a more confident comparison). Default 1.\n */\n weight?: number\n}\n\nexport interface BradleyTerryRating {\n candidateId: string\n /** Latent strength θ ≥ 0 from the BT MLE. */\n strength: number\n /** Log-strength = log(θ) — interpretable on a linear scale. */\n logStrength: number\n /** Number of pairwise comparisons this candidate appears in. */\n n: number\n /** Win count (+ 0.5 per draw). */\n wins: number\n}\n\nexport interface BradleyTerryFit {\n ratings: BradleyTerryRating[]\n /** Iterations of the MM algorithm before convergence. */\n iterations: number\n /** Final maximum |θ_new - θ_old| / θ_old. */\n finalDelta: number\n converged: boolean\n}\n\n/**\n * Bradley-Terry MLE via Hunter's MM algorithm.\n *\n * Iteration: θ_i^new = W_i / Σ_{j ≠ i} N_ij / (θ_i + θ_j)\n * where W_i = wins by i (+ 0.5 per draw), N_ij = total comparisons.\n *\n * Returns log-strengths normalized so the smallest is 0 (any constant\n * offset is unobservable in BT — only differences are identified).\n */\nexport function fitBradleyTerry(\n outcomes: PairwiseOutcome[],\n opts: { tolerance?: number; maxIterations?: number; smoothing?: number } = {},\n): BradleyTerryFit {\n const tol = opts.tolerance ?? 1e-6\n const maxIter = opts.maxIterations ?? 256\n // Small positive default — Hunter's MM degenerates when a candidate has\n // zero wins (θ → 0 → log → -∞). 0.1 is negligible against real win counts\n // (~1 win / 10 comparisons) and keeps the iteration well-conditioned.\n // Override to 0 if the comparison set is guaranteed strongly connected.\n const smoothing = opts.smoothing ?? 0.1\n\n const candidates = new Set<string>()\n for (const o of outcomes) {\n candidates.add(o.winner)\n candidates.add(o.loser)\n }\n const ids = [...candidates].sort()\n const idx = new Map(ids.map((id, i) => [id, i]))\n const n = ids.length\n if (n === 0) return { ratings: [], iterations: 0, finalDelta: 0, converged: true }\n if (n === 1) {\n return {\n ratings: [{ candidateId: ids[0]!, strength: 1, logStrength: 0, n: 0, wins: 0 }],\n iterations: 0,\n finalDelta: 0,\n converged: true,\n }\n }\n\n // Build win matrix W[i][j] = (weighted) wins of i over j, plus half for draws.\n // Build comparison matrix N[i][j] = total weighted comparisons between i and j.\n const W: number[][] = Array.from({ length: n }, () => new Array<number>(n).fill(0))\n const N: number[][] = Array.from({ length: n }, () => new Array<number>(n).fill(0))\n for (const o of outcomes) {\n const i = idx.get(o.winner)!\n const j = idx.get(o.loser)!\n const w = o.weight ?? 1\n if (o.draw) {\n W[i]![j]! += 0.5 * w\n W[j]![i]! += 0.5 * w\n } else {\n W[i]![j]! += w\n }\n N[i]![j]! += w\n N[j]![i]! += w\n }\n\n // Per-candidate total wins.\n const winsTotal = new Array<number>(n).fill(0)\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) winsTotal[i]! += W[i]![j]!\n winsTotal[i]! += smoothing // tiny smoothing to keep θ positive\n }\n const compsTotal = new Array<number>(n).fill(0)\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) compsTotal[i]! += N[i]![j]!\n }\n\n // MM iterations.\n let theta = new Array<number>(n).fill(1)\n let iter = 0\n let delta = Infinity\n for (; iter < maxIter; iter++) {\n const newTheta = new Array<number>(n)\n for (let i = 0; i < n; i++) {\n let denom = 0\n for (let j = 0; j < n; j++) {\n if (j === i) continue\n if (N[i]![j]! === 0) continue\n denom += N[i]![j]! / (theta[i]! + theta[j]!)\n }\n newTheta[i] = denom === 0 ? theta[i]! : winsTotal[i]! / denom\n }\n // Normalize so geometric mean = 1 (numerical stability).\n let logSum = 0\n for (let i = 0; i < n; i++) logSum += Math.log(Math.max(1e-300, newTheta[i]!))\n const norm = Math.exp(logSum / n)\n for (let i = 0; i < n; i++) newTheta[i] = newTheta[i]! / norm\n\n delta = 0\n for (let i = 0; i < n; i++) {\n const d = Math.abs(newTheta[i]! - theta[i]!) / Math.max(1e-12, theta[i]!)\n if (d > delta) delta = d\n }\n theta = newTheta\n if (delta < tol) break\n }\n\n const minLog = Math.min(...theta.map((t) => Math.log(Math.max(1e-300, t))))\n const ratings: BradleyTerryRating[] = ids.map((id, i) => ({\n candidateId: id,\n strength: theta[i]!,\n logStrength: Math.log(Math.max(1e-300, theta[i]!)) - minLog,\n n: compsTotal[i]!,\n wins: winsTotal[i]! - smoothing,\n }))\n\n return {\n ratings: ratings.sort((a, b) => b.strength - a.strength),\n iterations: iter,\n finalDelta: delta,\n converged: delta < tol,\n }\n}\n\n/**\n * Online Elo updates. Use when comparisons arrive over time and you want\n * a running rating without re-fitting the full BT MLE on every update.\n *\n * Initialize ratings to `defaultRating` (1500 by default). Each call to\n * `applyEloUpdate` mutates the map in place and returns the deltas so\n * the caller can log per-comparison rating changes.\n */\nexport interface EloOptions {\n /** Default rating for unseen candidates. Default 1500. */\n defaultRating?: number\n /** K-factor controls the step size. Default 32 (FIDE-ish). */\n kFactor?: number\n}\n\nexport function applyEloUpdate(\n ratings: Map<string, number>,\n outcome: PairwiseOutcome,\n opts: EloOptions = {},\n): { winnerDelta: number; loserDelta: number } {\n const defaultRating = opts.defaultRating ?? 1500\n const k = opts.kFactor ?? 32\n\n const rW = ratings.get(outcome.winner) ?? defaultRating\n const rL = ratings.get(outcome.loser) ?? defaultRating\n\n const expectedW = 1 / (1 + 10 ** ((rL - rW) / 400))\n const scoreW = outcome.draw ? 0.5 : 1\n const scoreL = outcome.draw ? 0.5 : 0\n const w = outcome.weight ?? 1\n\n const winnerDelta = k * w * (scoreW - expectedW)\n const loserDelta = k * w * (scoreL - (1 - expectedW))\n\n ratings.set(outcome.winner, rW + winnerDelta)\n ratings.set(outcome.loser, rL + loserDelta)\n\n return { winnerDelta, loserDelta }\n}\n\n/**\n * Build pairwise outcomes from the campaign artifact: for every scenario\n * shared by two candidates, the higher-scoring run wins. Useful when you\n * want a tournament view of an existing campaign without an additional\n * pairwise judge call.\n */\nexport interface BuildPairwiseFromCampaignInput {\n runs: Array<{\n candidateId: string\n /** Stable identifier for the matching unit (typically scenarioId). */\n matchKey: string\n score: number\n }>\n /**\n * Tied-score margin. Below this, the comparison is a draw. Default 0\n * (no ties).\n */\n drawMargin?: number\n}\n\nexport function buildPairwiseFromCampaign(\n input: BuildPairwiseFromCampaignInput,\n): PairwiseOutcome[] {\n const drawMargin = input.drawMargin ?? 0\n const byKey = new Map<string, Array<{ candidateId: string; score: number }>>()\n for (const r of input.runs) {\n const arr = byKey.get(r.matchKey) ?? []\n arr.push({ candidateId: r.candidateId, score: r.score })\n byKey.set(r.matchKey, arr)\n }\n const outcomes: PairwiseOutcome[] = []\n for (const arr of byKey.values()) {\n for (let i = 0; i < arr.length; i++) {\n for (let j = i + 1; j < arr.length; j++) {\n const a = arr[i]!\n const b = arr[j]!\n if (a.candidateId === b.candidateId) continue\n const margin = Math.abs(a.score - b.score)\n if (margin <= drawMargin) {\n outcomes.push({ winner: a.candidateId, loser: b.candidateId, draw: true, weight: 1 })\n } else {\n const [winner, loser] = a.score > b.score ? [a, b] : [b, a]\n outcomes.push({ winner: winner.candidateId, loser: loser.candidateId, weight: margin })\n }\n }\n }\n }\n return outcomes\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyEA,eAAsB,mBACpB,MAC0B;AAC1B,QAAM,KAAK,KAAK,MAAM,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE;AACxC,QAAM,OAAO,KAAK,QAAQ;AAC1B,QAAM,gBAAgB,KAAK,iBAAiB;AAC5C,QAAM,WAAW,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC;AAE7C,QAAM,SAA4B,CAAC;AACnC,aAAW,KAAK,UAAU;AACxB,UAAM,cAA8C,CAAC;AACrD,UAAM,YAAsB,CAAC;AAC7B,QAAI,cAAc;AAClB,QAAI,gBAAgB;AACpB,eAAW,YAAY,KAAK,WAAW;AACrC,YAAM,MAAM,SAAS,cAAc,YAAY,KAAK,UAAU,QAAQ,QAAQ,CAAC;AAC/E,YAAM,SAAmB,CAAC;AAC1B,UAAI,SAAS;AACb,eAAS,IAAI,GAAG,IAAI,MAAM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
|
5
|
-
import "./chunk-PJQFMIOX.js";
|
|
6
|
-
import "./chunk-JHOJHHU7.js";
|
|
7
|
-
import "./chunk-VI2UW6B6.js";
|
|
8
|
-
import "./chunk-ONWEPEDO.js";
|
|
9
|
-
import "./chunk-PZ5AY32C.js";
|
|
10
|
-
export {
|
|
11
|
-
planCampaignRun,
|
|
12
|
-
runCampaign
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=run-campaign-HNFPJET4.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|