@axlsdk/eval 0.22.2 → 0.23.0
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/README.md +7 -4
- package/dist/{chunk-C7CICWIA.js → chunk-FQHKBSZD.js} +51 -3
- package/dist/chunk-FQHKBSZD.js.map +1 -0
- package/dist/cli.cjs +69 -2
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +20 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +50 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +107 -1
- package/dist/index.d.ts +107 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-C7CICWIA.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -273,6 +273,93 @@ type ScorerDetail = {
|
|
|
273
273
|
*/
|
|
274
274
|
skipped?: boolean;
|
|
275
275
|
};
|
|
276
|
+
/**
|
|
277
|
+
* Provider-call latency sums for one model within one eval item, rolled up from
|
|
278
|
+
* the `timing` block on `agent_call_end` (see `CallTiming` in `@axlsdk/axl`).
|
|
279
|
+
*
|
|
280
|
+
* The point of the split is that `EvalItem.duration` is wall clock for the whole
|
|
281
|
+
* workflow — tools, gates, the SDK's own rate-limiter queue and all — so it
|
|
282
|
+
* cannot be compared across models or across runs with different fan-out.
|
|
283
|
+
* `wireMs` is the provider's time; `queuedMs` is the SDK's self-imposed pacing;
|
|
284
|
+
* `retryMs` is failed attempts and their backoff.
|
|
285
|
+
*
|
|
286
|
+
* Keyed by the effective model URI (`openai:gpt-4o`), the same key
|
|
287
|
+
* `metadata.modelCallCounts` uses, so the two can be joined.
|
|
288
|
+
*/
|
|
289
|
+
type ItemModelTiming = {
|
|
290
|
+
/** Provider calls that REPORTED timing. May be lower than this model's
|
|
291
|
+
* `modelCallCounts` entry — an uninstrumented custom provider and the error
|
|
292
|
+
* path both contribute a call with no timing. Divide the sums by this, never
|
|
293
|
+
* by the call count. */
|
|
294
|
+
calls: number;
|
|
295
|
+
/** Sum of `CallTiming.queuedMs` — waiting on the SDK's own rate limiter. */
|
|
296
|
+
queuedMs: number;
|
|
297
|
+
/** Sum of `CallTiming.retryMs` — failed attempts plus their backoff. */
|
|
298
|
+
retryMs: number;
|
|
299
|
+
/** Sum of `CallTiming.wireMs` — time attributable to the provider. Across
|
|
300
|
+
* concurrent calls this can exceed the item's `duration`; that is expected. */
|
|
301
|
+
wireMs: number;
|
|
302
|
+
/** Sum of `CallTiming.firstTokenMs` over the STREAMING calls that reported
|
|
303
|
+
* one. Absent when no call did, so a non-streaming model reports no
|
|
304
|
+
* misleading `0`. Its denominator is `firstTokenCalls`, NOT `calls`. */
|
|
305
|
+
firstTokenMs?: number;
|
|
306
|
+
/** Timed calls that reported a `firstTokenMs`. Present exactly when
|
|
307
|
+
* `firstTokenMs` is. It exists because a model can mix streamed and
|
|
308
|
+
* non-streamed calls, and dividing the first-token sum by `calls` would then
|
|
309
|
+
* report a latency no call ever achieved. */
|
|
310
|
+
firstTokenCalls?: number;
|
|
311
|
+
};
|
|
312
|
+
/** Distribution shape shared by the wall-clock and per-model timing stats. */
|
|
313
|
+
type TimingStats = {
|
|
314
|
+
mean: number;
|
|
315
|
+
min: number;
|
|
316
|
+
max: number;
|
|
317
|
+
p50: number;
|
|
318
|
+
p95: number;
|
|
319
|
+
};
|
|
320
|
+
/**
|
|
321
|
+
* Per-model latency stats across a run, on `EvalSummary.modelTiming`.
|
|
322
|
+
*
|
|
323
|
+
* Every field here is a distribution over **per-call** values, pooled across all
|
|
324
|
+
* of the run's successful items — the same population `calls` counts. One
|
|
325
|
+
* provider call is one sample, so an item that makes ten calls weighs ten times
|
|
326
|
+
* an item that makes one. That is the right weighting for a model comparison:
|
|
327
|
+
* these numbers describe the model's latency, not the item's.
|
|
328
|
+
*
|
|
329
|
+
* This is deliberately a different weighting from the wall-clock
|
|
330
|
+
* `EvalSummary.timing`, which samples once per item because it describes the
|
|
331
|
+
* workflow. Read them side by side; do not expect them to agree.
|
|
332
|
+
*/
|
|
333
|
+
type ModelTimingStats = {
|
|
334
|
+
/** Total SUCCESSFUL timed provider calls for this model across every item —
|
|
335
|
+
* the sample size behind every distribution below. May be lower than this
|
|
336
|
+
* model's total call count: an uninstrumented provider reports no timing, and
|
|
337
|
+
* a failed call is excluded even when it does report one, so these stats
|
|
338
|
+
* describe answers rather than a blend of answers and failures. */
|
|
339
|
+
calls: number;
|
|
340
|
+
/** Per-call wire latency (ms) — time attributable to the provider. The
|
|
341
|
+
* primary model-comparison figure alongside `firstTokenMs`. */
|
|
342
|
+
wireMs: TimingStats;
|
|
343
|
+
/** Per-call queue wait (ms) in Axl's own rate limiter. Self-imposed wait, so
|
|
344
|
+
* it never distorts a comparison of the models themselves. */
|
|
345
|
+
queuedMs: TimingStats;
|
|
346
|
+
/** Per-call retry time (ms) — failed attempts and their backoff. A model
|
|
347
|
+
* throttled hard on the day of the run shows it here, which is what keeps
|
|
348
|
+
* `wireMs` an honest comparison. */
|
|
349
|
+
retryMs: TimingStats;
|
|
350
|
+
/** Per-call time to first content delta (ms), over the STREAMING calls that
|
|
351
|
+
* reported one — non-streaming calls are excluded from the sample rather
|
|
352
|
+
* than entered as `0`. Absent when no call reported one. This is the
|
|
353
|
+
* model-discriminating figure: response headers arrive at roughly one round
|
|
354
|
+
* trip regardless of model, first token does not. */
|
|
355
|
+
firstTokenMs?: TimingStats;
|
|
356
|
+
/** How many calls that `firstTokenMs` sample covers. It earns its place
|
|
357
|
+
* because a `TimingStats` carries no sample size, so on a model that mixes
|
|
358
|
+
* streamed and non-streamed calls there is otherwise no way to tell a
|
|
359
|
+
* first-token figure drawn from one call apart from one drawn from all of
|
|
360
|
+
* them. Present exactly when `firstTokenMs` is. */
|
|
361
|
+
firstTokenCalls?: number;
|
|
362
|
+
};
|
|
276
363
|
type EvalItem = {
|
|
277
364
|
input: unknown;
|
|
278
365
|
annotations?: unknown;
|
|
@@ -288,6 +375,20 @@ type EvalItem = {
|
|
|
288
375
|
scoreDetails?: Record<string, ScorerDetail>;
|
|
289
376
|
/** Execution metadata forwarded from the runtime (models, tokens, agentCalls, etc). */
|
|
290
377
|
metadata?: Record<string, unknown>;
|
|
378
|
+
/** Per-model provider-call latency for this item, rolled up from
|
|
379
|
+
* `agent_call_end.timing`. Absent when the item made no timed provider call
|
|
380
|
+
* — an item with no ask, an uninstrumented custom provider, or a runtime
|
|
381
|
+
* without `trackExecution`. Distinct from `duration` (workflow wall clock),
|
|
382
|
+
* which is unchanged.
|
|
383
|
+
*
|
|
384
|
+
* These are per-item SUMS, kept compact so a persisted artifact stays small.
|
|
385
|
+
* `summary.modelTiming` is NOT derived from them — it is computed from the
|
|
386
|
+
* raw per-call blocks while the run is in memory, so its percentiles are
|
|
387
|
+
* real per-call percentiles rather than percentiles of item means. A
|
|
388
|
+
* consumer holding only a saved artifact can therefore recover per-item
|
|
389
|
+
* sums and per-model totals from `item.timing`, but not the distribution.
|
|
390
|
+
* (`rescore` already reports no timing stats at all, so nothing regresses.) */
|
|
391
|
+
timing?: Record<string, ItemModelTiming>;
|
|
291
392
|
/** Trace events captured during this item's execution. Only populated when
|
|
292
393
|
* `runEval` was called with `{ captureTraces: true }`. Verbose-mode
|
|
293
394
|
* `agent_call_start.data.messages` snapshots are stripped to keep memory bounded;
|
|
@@ -327,6 +428,8 @@ type EvalSummary = {
|
|
|
327
428
|
*/
|
|
328
429
|
skipped?: number;
|
|
329
430
|
}>;
|
|
431
|
+
/** Wall-clock stats over per-item `duration`. Unchanged by the per-model
|
|
432
|
+
* timing rollup — this still measures the whole workflow, queue and all. */
|
|
330
433
|
timing?: {
|
|
331
434
|
mean: number;
|
|
332
435
|
min: number;
|
|
@@ -334,6 +437,9 @@ type EvalSummary = {
|
|
|
334
437
|
p50: number;
|
|
335
438
|
p95: number;
|
|
336
439
|
};
|
|
440
|
+
/** Per-model provider-latency stats, present only when at least one item
|
|
441
|
+
* reported timing. Read alongside `timing`, never instead of it. */
|
|
442
|
+
modelTiming?: Record<string, ModelTimingStats>;
|
|
337
443
|
/**
|
|
338
444
|
* Populated by `runEval` ONLY when `EvalConfig.failOnScorerErrorRate` is set
|
|
339
445
|
* and one or more scorers exceeded tolerance. `runEval` never throws on this
|
|
@@ -633,4 +739,4 @@ type MultiRunSummary = {
|
|
|
633
739
|
*/
|
|
634
740
|
declare function aggregateRuns(runs: EvalResult[]): MultiRunSummary;
|
|
635
741
|
|
|
636
|
-
export { type BootstrapCIResult, type Dataset, type DatasetConfig, type DatasetItem, type DegradedScorer, type EvalCompareOptions, type EvalComparison, type EvalComparisonPartial, type EvalConfig, type EvalImprovement, type EvalItem, type EvalProgressEvent, type EvalRegression, type EvalResult, type EvalSummary, type ExtraKeyPolicy, type LlmScorerConfig, type MultiRunSummary, type RescoreOptions, type RunEvalOptions, type Scorer, type ScorerApplies, type ScorerConfig, type ScorerContext, type ScorerDetail, type ScorerFn, type ScorerResult, type ScorerToleranceVerdict, aggregateRuns, dataset, defineEval, evalCompare, evaluateScorerErrorRateGate, evaluateScorerTolerance, llmScorer, normalizeScorerResult, pairedBootstrapCI, rescore, runEval, scorer };
|
|
742
|
+
export { type BootstrapCIResult, type Dataset, type DatasetConfig, type DatasetItem, type DegradedScorer, type EvalCompareOptions, type EvalComparison, type EvalComparisonPartial, type EvalConfig, type EvalImprovement, type EvalItem, type EvalProgressEvent, type EvalRegression, type EvalResult, type EvalSummary, type ExtraKeyPolicy, type ItemModelTiming, type LlmScorerConfig, type ModelTimingStats, type MultiRunSummary, type RescoreOptions, type RunEvalOptions, type Scorer, type ScorerApplies, type ScorerConfig, type ScorerContext, type ScorerDetail, type ScorerFn, type ScorerResult, type ScorerToleranceVerdict, aggregateRuns, dataset, defineEval, evalCompare, evaluateScorerErrorRateGate, evaluateScorerTolerance, llmScorer, normalizeScorerResult, pairedBootstrapCI, rescore, runEval, scorer };
|
package/dist/index.d.ts
CHANGED
|
@@ -273,6 +273,93 @@ type ScorerDetail = {
|
|
|
273
273
|
*/
|
|
274
274
|
skipped?: boolean;
|
|
275
275
|
};
|
|
276
|
+
/**
|
|
277
|
+
* Provider-call latency sums for one model within one eval item, rolled up from
|
|
278
|
+
* the `timing` block on `agent_call_end` (see `CallTiming` in `@axlsdk/axl`).
|
|
279
|
+
*
|
|
280
|
+
* The point of the split is that `EvalItem.duration` is wall clock for the whole
|
|
281
|
+
* workflow — tools, gates, the SDK's own rate-limiter queue and all — so it
|
|
282
|
+
* cannot be compared across models or across runs with different fan-out.
|
|
283
|
+
* `wireMs` is the provider's time; `queuedMs` is the SDK's self-imposed pacing;
|
|
284
|
+
* `retryMs` is failed attempts and their backoff.
|
|
285
|
+
*
|
|
286
|
+
* Keyed by the effective model URI (`openai:gpt-4o`), the same key
|
|
287
|
+
* `metadata.modelCallCounts` uses, so the two can be joined.
|
|
288
|
+
*/
|
|
289
|
+
type ItemModelTiming = {
|
|
290
|
+
/** Provider calls that REPORTED timing. May be lower than this model's
|
|
291
|
+
* `modelCallCounts` entry — an uninstrumented custom provider and the error
|
|
292
|
+
* path both contribute a call with no timing. Divide the sums by this, never
|
|
293
|
+
* by the call count. */
|
|
294
|
+
calls: number;
|
|
295
|
+
/** Sum of `CallTiming.queuedMs` — waiting on the SDK's own rate limiter. */
|
|
296
|
+
queuedMs: number;
|
|
297
|
+
/** Sum of `CallTiming.retryMs` — failed attempts plus their backoff. */
|
|
298
|
+
retryMs: number;
|
|
299
|
+
/** Sum of `CallTiming.wireMs` — time attributable to the provider. Across
|
|
300
|
+
* concurrent calls this can exceed the item's `duration`; that is expected. */
|
|
301
|
+
wireMs: number;
|
|
302
|
+
/** Sum of `CallTiming.firstTokenMs` over the STREAMING calls that reported
|
|
303
|
+
* one. Absent when no call did, so a non-streaming model reports no
|
|
304
|
+
* misleading `0`. Its denominator is `firstTokenCalls`, NOT `calls`. */
|
|
305
|
+
firstTokenMs?: number;
|
|
306
|
+
/** Timed calls that reported a `firstTokenMs`. Present exactly when
|
|
307
|
+
* `firstTokenMs` is. It exists because a model can mix streamed and
|
|
308
|
+
* non-streamed calls, and dividing the first-token sum by `calls` would then
|
|
309
|
+
* report a latency no call ever achieved. */
|
|
310
|
+
firstTokenCalls?: number;
|
|
311
|
+
};
|
|
312
|
+
/** Distribution shape shared by the wall-clock and per-model timing stats. */
|
|
313
|
+
type TimingStats = {
|
|
314
|
+
mean: number;
|
|
315
|
+
min: number;
|
|
316
|
+
max: number;
|
|
317
|
+
p50: number;
|
|
318
|
+
p95: number;
|
|
319
|
+
};
|
|
320
|
+
/**
|
|
321
|
+
* Per-model latency stats across a run, on `EvalSummary.modelTiming`.
|
|
322
|
+
*
|
|
323
|
+
* Every field here is a distribution over **per-call** values, pooled across all
|
|
324
|
+
* of the run's successful items — the same population `calls` counts. One
|
|
325
|
+
* provider call is one sample, so an item that makes ten calls weighs ten times
|
|
326
|
+
* an item that makes one. That is the right weighting for a model comparison:
|
|
327
|
+
* these numbers describe the model's latency, not the item's.
|
|
328
|
+
*
|
|
329
|
+
* This is deliberately a different weighting from the wall-clock
|
|
330
|
+
* `EvalSummary.timing`, which samples once per item because it describes the
|
|
331
|
+
* workflow. Read them side by side; do not expect them to agree.
|
|
332
|
+
*/
|
|
333
|
+
type ModelTimingStats = {
|
|
334
|
+
/** Total SUCCESSFUL timed provider calls for this model across every item —
|
|
335
|
+
* the sample size behind every distribution below. May be lower than this
|
|
336
|
+
* model's total call count: an uninstrumented provider reports no timing, and
|
|
337
|
+
* a failed call is excluded even when it does report one, so these stats
|
|
338
|
+
* describe answers rather than a blend of answers and failures. */
|
|
339
|
+
calls: number;
|
|
340
|
+
/** Per-call wire latency (ms) — time attributable to the provider. The
|
|
341
|
+
* primary model-comparison figure alongside `firstTokenMs`. */
|
|
342
|
+
wireMs: TimingStats;
|
|
343
|
+
/** Per-call queue wait (ms) in Axl's own rate limiter. Self-imposed wait, so
|
|
344
|
+
* it never distorts a comparison of the models themselves. */
|
|
345
|
+
queuedMs: TimingStats;
|
|
346
|
+
/** Per-call retry time (ms) — failed attempts and their backoff. A model
|
|
347
|
+
* throttled hard on the day of the run shows it here, which is what keeps
|
|
348
|
+
* `wireMs` an honest comparison. */
|
|
349
|
+
retryMs: TimingStats;
|
|
350
|
+
/** Per-call time to first content delta (ms), over the STREAMING calls that
|
|
351
|
+
* reported one — non-streaming calls are excluded from the sample rather
|
|
352
|
+
* than entered as `0`. Absent when no call reported one. This is the
|
|
353
|
+
* model-discriminating figure: response headers arrive at roughly one round
|
|
354
|
+
* trip regardless of model, first token does not. */
|
|
355
|
+
firstTokenMs?: TimingStats;
|
|
356
|
+
/** How many calls that `firstTokenMs` sample covers. It earns its place
|
|
357
|
+
* because a `TimingStats` carries no sample size, so on a model that mixes
|
|
358
|
+
* streamed and non-streamed calls there is otherwise no way to tell a
|
|
359
|
+
* first-token figure drawn from one call apart from one drawn from all of
|
|
360
|
+
* them. Present exactly when `firstTokenMs` is. */
|
|
361
|
+
firstTokenCalls?: number;
|
|
362
|
+
};
|
|
276
363
|
type EvalItem = {
|
|
277
364
|
input: unknown;
|
|
278
365
|
annotations?: unknown;
|
|
@@ -288,6 +375,20 @@ type EvalItem = {
|
|
|
288
375
|
scoreDetails?: Record<string, ScorerDetail>;
|
|
289
376
|
/** Execution metadata forwarded from the runtime (models, tokens, agentCalls, etc). */
|
|
290
377
|
metadata?: Record<string, unknown>;
|
|
378
|
+
/** Per-model provider-call latency for this item, rolled up from
|
|
379
|
+
* `agent_call_end.timing`. Absent when the item made no timed provider call
|
|
380
|
+
* — an item with no ask, an uninstrumented custom provider, or a runtime
|
|
381
|
+
* without `trackExecution`. Distinct from `duration` (workflow wall clock),
|
|
382
|
+
* which is unchanged.
|
|
383
|
+
*
|
|
384
|
+
* These are per-item SUMS, kept compact so a persisted artifact stays small.
|
|
385
|
+
* `summary.modelTiming` is NOT derived from them — it is computed from the
|
|
386
|
+
* raw per-call blocks while the run is in memory, so its percentiles are
|
|
387
|
+
* real per-call percentiles rather than percentiles of item means. A
|
|
388
|
+
* consumer holding only a saved artifact can therefore recover per-item
|
|
389
|
+
* sums and per-model totals from `item.timing`, but not the distribution.
|
|
390
|
+
* (`rescore` already reports no timing stats at all, so nothing regresses.) */
|
|
391
|
+
timing?: Record<string, ItemModelTiming>;
|
|
291
392
|
/** Trace events captured during this item's execution. Only populated when
|
|
292
393
|
* `runEval` was called with `{ captureTraces: true }`. Verbose-mode
|
|
293
394
|
* `agent_call_start.data.messages` snapshots are stripped to keep memory bounded;
|
|
@@ -327,6 +428,8 @@ type EvalSummary = {
|
|
|
327
428
|
*/
|
|
328
429
|
skipped?: number;
|
|
329
430
|
}>;
|
|
431
|
+
/** Wall-clock stats over per-item `duration`. Unchanged by the per-model
|
|
432
|
+
* timing rollup — this still measures the whole workflow, queue and all. */
|
|
330
433
|
timing?: {
|
|
331
434
|
mean: number;
|
|
332
435
|
min: number;
|
|
@@ -334,6 +437,9 @@ type EvalSummary = {
|
|
|
334
437
|
p50: number;
|
|
335
438
|
p95: number;
|
|
336
439
|
};
|
|
440
|
+
/** Per-model provider-latency stats, present only when at least one item
|
|
441
|
+
* reported timing. Read alongside `timing`, never instead of it. */
|
|
442
|
+
modelTiming?: Record<string, ModelTimingStats>;
|
|
337
443
|
/**
|
|
338
444
|
* Populated by `runEval` ONLY when `EvalConfig.failOnScorerErrorRate` is set
|
|
339
445
|
* and one or more scorers exceeded tolerance. `runEval` never throws on this
|
|
@@ -633,4 +739,4 @@ type MultiRunSummary = {
|
|
|
633
739
|
*/
|
|
634
740
|
declare function aggregateRuns(runs: EvalResult[]): MultiRunSummary;
|
|
635
741
|
|
|
636
|
-
export { type BootstrapCIResult, type Dataset, type DatasetConfig, type DatasetItem, type DegradedScorer, type EvalCompareOptions, type EvalComparison, type EvalComparisonPartial, type EvalConfig, type EvalImprovement, type EvalItem, type EvalProgressEvent, type EvalRegression, type EvalResult, type EvalSummary, type ExtraKeyPolicy, type LlmScorerConfig, type MultiRunSummary, type RescoreOptions, type RunEvalOptions, type Scorer, type ScorerApplies, type ScorerConfig, type ScorerContext, type ScorerDetail, type ScorerFn, type ScorerResult, type ScorerToleranceVerdict, aggregateRuns, dataset, defineEval, evalCompare, evaluateScorerErrorRateGate, evaluateScorerTolerance, llmScorer, normalizeScorerResult, pairedBootstrapCI, rescore, runEval, scorer };
|
|
742
|
+
export { type BootstrapCIResult, type Dataset, type DatasetConfig, type DatasetItem, type DegradedScorer, type EvalCompareOptions, type EvalComparison, type EvalComparisonPartial, type EvalConfig, type EvalImprovement, type EvalItem, type EvalProgressEvent, type EvalRegression, type EvalResult, type EvalSummary, type ExtraKeyPolicy, type ItemModelTiming, type LlmScorerConfig, type ModelTimingStats, type MultiRunSummary, type RescoreOptions, type RunEvalOptions, type Scorer, type ScorerApplies, type ScorerConfig, type ScorerContext, type ScorerDetail, type ScorerFn, type ScorerResult, type ScorerToleranceVerdict, aggregateRuns, dataset, defineEval, evalCompare, evaluateScorerErrorRateGate, evaluateScorerTolerance, llmScorer, normalizeScorerResult, pairedBootstrapCI, rescore, runEval, scorer };
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axlsdk/eval",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Evaluation framework for Axl agentic workflows",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@axlsdk/axl": "0.
|
|
28
|
+
"@axlsdk/axl": "0.23.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"zod": "^4.0.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bootstrap.ts","../src/utils.ts","../src/compare.ts","../src/scorer.ts","../src/score-item.ts","../src/runner.ts","../src/rescore.ts","../src/multi-run.ts"],"sourcesContent":["export type BootstrapCIResult = {\n /** Lower bound of the confidence interval. */\n lower: number;\n /** Upper bound of the confidence interval. */\n upper: number;\n /** Mean of the original differences. */\n mean: number;\n /** Proportion of resamples where the mean difference is negative (probability of regression). */\n pRegression: number;\n /** Proportion of resamples where the mean difference is positive (probability of improvement). */\n pImprovement: number;\n};\n\n/**\n * Compute a bootstrap confidence interval on paired differences.\n *\n * Resamples the differences array with replacement, computes the mean of each\n * resample, and returns the percentile-based confidence interval.\n */\nexport function pairedBootstrapCI(\n differences: number[],\n options?: { nResamples?: number; alpha?: number; seed?: number },\n): BootstrapCIResult {\n const n = differences.length;\n if (n === 0) return { lower: 0, upper: 0, mean: 0, pRegression: 0, pImprovement: 0 };\n\n const nResamples = options?.nResamples ?? 1000;\n const alpha = options?.alpha ?? 0.05;\n\n const mean = differences.reduce((a, b) => a + b, 0) / n;\n\n if (n === 1)\n return {\n lower: differences[0],\n upper: differences[0],\n mean,\n pRegression: mean < 0 ? 1 : 0,\n pImprovement: mean > 0 ? 1 : 0,\n };\n\n if (nResamples <= 0)\n return {\n lower: round(mean),\n upper: round(mean),\n mean: round(mean),\n pRegression: mean < 0 ? 1 : 0,\n pImprovement: mean > 0 ? 1 : 0,\n };\n\n // Seeded or random number generator\n const rng = options?.seed != null ? xorshift32(options.seed) : () => Math.random();\n\n const resampleMeans: number[] = new Array(nResamples);\n for (let r = 0; r < nResamples; r++) {\n let sum = 0;\n for (let i = 0; i < n; i++) {\n sum += differences[Math.floor(rng() * n)];\n }\n resampleMeans[r] = sum / n;\n }\n\n resampleMeans.sort((a, b) => a - b);\n\n const lowerIdx = Math.floor((alpha / 2) * nResamples);\n const upperIdx = Math.floor((1 - alpha / 2) * nResamples) - 1;\n\n // Count resamples below/above zero for directional probabilities\n // resampleMeans is already sorted, so binary search for zero\n let belowZero = 0;\n for (let i = 0; i < nResamples; i++) {\n if (resampleMeans[i] < 0) belowZero++;\n else break;\n }\n let aboveZero = 0;\n for (let i = nResamples - 1; i >= 0; i--) {\n if (resampleMeans[i] > 0) aboveZero++;\n else break;\n }\n\n return {\n lower: round(resampleMeans[Math.max(0, lowerIdx)]),\n upper: round(resampleMeans[Math.min(nResamples - 1, upperIdx)]),\n mean: round(mean),\n pRegression: round(belowZero / nResamples),\n pImprovement: round(aboveZero / nResamples),\n };\n}\n\nfunction round(n: number): number {\n return Math.round(n * 10000) / 10000;\n}\n\n/** Simple xorshift32 PRNG for deterministic test behavior. Returns values in [0, 1). */\nfunction xorshift32(seed: number): () => number {\n let state = seed | 0 || 1; // Ensure non-zero\n return () => {\n state ^= state << 13;\n state ^= state >> 17;\n state ^= state << 5;\n return (state >>> 0) / 0x100000000;\n };\n}\n","export function computeStats(scores: number[]): {\n mean: number;\n min: number;\n max: number;\n p50: number;\n p95: number;\n} {\n if (scores.length === 0) return { mean: 0, min: 0, max: 0, p50: 0, p95: 0 };\n const sorted = [...scores].sort((a, b) => a - b);\n const mean = sorted.reduce((a, b) => a + b, 0) / sorted.length;\n const min = sorted[0];\n const max = sorted[sorted.length - 1];\n const p50 = sorted[Math.floor(sorted.length * 0.5)];\n const p95 = sorted[Math.floor(sorted.length * 0.95)];\n return { mean: round(mean), min: round(min), max: round(max), p50: round(p50), p95: round(p95) };\n}\n\nexport function round(n: number): number {\n return Math.round(n * 1000) / 1000;\n}\n\n/**\n * Count, for one scorer across a set of items, how many produced a valid score\n * (`scored`), ran-and-failed (`failed`), or were deliberately skipped by the\n * scorer's `applies` predicate (`skipped`). The single source of truth for the\n * failure-rate trust signal, shared by `runEval`, `rescore`, and `evalCompare`.\n *\n * Three discriminators on the per-scorer `scoreDetails` entry, checked in\n * precedence order so a positive `skipped` marker always wins over the\n * duration heuristic:\n * - a non-null `scores[name]` ⇒ `scored`;\n * - else `skipped === true` (the `applies` predicate returned `false`) ⇒\n * `skipped` — deliberately NOT run, so it belongs in neither the mean nor\n * the failure-rate denominator;\n * - else a `duration` ⇒ `failed` (`scoreItem` stamps it whenever a scorer\n * actually executes: success, throw, or out-of-range);\n * - else (no score, no marker, no duration) the scorer was skipped by\n * cancellation (signal aborted before it started) and belongs in no bucket.\n *\n * So `scored + failed` is the honest \"attempted\" denominator for a failure rate\n * — it excludes both `applies`-skips and cancellations and can be `<` the\n * eligible item count.\n *\n * Items whose WORKFLOW errored (`i.error`) are excluded entirely — the scorers\n * never ran for them, so they're not part of the scorer's sample either way.\n */\nexport function scorerCounts(\n items: readonly {\n error?: string;\n scores: Record<string, number | null>;\n scoreDetails?: Record<string, { duration?: number; skipped?: boolean }>;\n }[],\n name: string,\n): { scored: number; failed: number; skipped: number } {\n let scored = 0;\n let failed = 0;\n let skipped = 0;\n for (const i of items) {\n if (i.error) continue;\n if (i.scores[name] != null) scored++;\n else if (i.scoreDetails?.[name]?.skipped === true) skipped++;\n else if (i.scoreDetails?.[name]?.duration != null) failed++;\n }\n return { scored, failed, skipped };\n}\n\n/** A scorer's failure-rate verdict against a tolerance — see {@link evaluateScorerTolerance}. */\nexport type ScorerToleranceVerdict = {\n /** `scored + failed` — the attempted denominator (excludes cancelled/never-run). */\n attempted: number;\n /** `failed / attempted`, or `0` when nothing was attempted. */\n rate: number;\n /** Over tolerance AND something was actually attempted. */\n exceeds: boolean;\n /** Nothing was attempted (`attempted === 0`) — no basis to certify a rate. */\n zeroSample: boolean;\n};\n\n/**\n * Single source of truth for the type-aware failure-rate decision, shared by the\n * source-side gate (`runEval` → `summary.degraded`) and the gate-side compare\n * gate (`evalCompare` consumers). Deterministic scorers tolerate ZERO failures\n * (a deterministic throw is a bug, not noise); LLM scorers tolerate up to `limit`\n * (`failed / attempted`). `exceeds` is never true when nothing was attempted —\n * callers decide their own policy for `zeroSample` (the runner skips it; the\n * compare gate refuses to certify a zero-sample scorer).\n */\nexport function evaluateScorerTolerance(\n scored: number,\n failed: number,\n type: 'llm' | 'deterministic',\n limit: number,\n): ScorerToleranceVerdict {\n const attempted = scored + failed;\n const rate = attempted === 0 ? 0 : failed / attempted;\n const exceeds = attempted > 0 && (type === 'deterministic' ? failed > 0 : rate > limit);\n return { attempted, rate, exceeds, zeroSample: attempted === 0 };\n}\n\n/**\n * Run `task` over `items` with a bounded worker pool, preserving input order.\n *\n * Results are written to a pre-allocated array at the item's original index, so\n * `results[i]` always corresponds to `items[i]` regardless of completion order.\n *\n * The helper does NOT catch — each `task` must own its try/catch. This is how\n * callers get `Promise.allSettled` semantics (one failing task never rejects\n * the whole batch) while still using a simple worker-pool: a task that resolves\n * (even after internally handling an error) lets the pool continue draining.\n *\n * Concurrency is clamped to `[1, items.length]` in exactly one place here, and\n * non-finite / fractional values are coerced (NaN/Infinity/`2.5` → a sane\n * integer). Callers must NOT pre-clamp with `Math.min(concurrency, items.length)`\n * and pass the result in — a user/env-supplied `0` (or `NaN` from a config like\n * `Number(process.env.X)`) would otherwise yield zero workers while items\n * remain, so `Promise.all` resolves immediately leaving the results array full\n * of holes (and the caller crashes on the `undefined` entries).\n */\nexport async function mapWithConcurrency<T, R = void>(\n items: readonly T[],\n concurrency: number,\n task: (item: T, index: number) => Promise<R>,\n): Promise<R[]> {\n const results = new Array<R>(items.length);\n // Coerce non-finite (NaN/Infinity) to the floor of 1, and floor fractional\n // values, BEFORE clamping — `Math.max(1, NaN)` is `NaN`, which would make\n // `Array.from({ length: NaN })` empty and silently run zero workers.\n const requested = Number.isFinite(concurrency) ? Math.floor(concurrency) : 1;\n const workerCount = items.length === 0 ? 0 : Math.min(Math.max(1, requested), items.length);\n\n let next = 0;\n async function runNext(): Promise<void> {\n while (next < items.length) {\n const i = next++;\n results[i] = await task(items[i], i);\n }\n }\n\n await Promise.all(Array.from({ length: workerCount }, () => runNext()));\n return results;\n}\n","import type {\n EvalResult,\n EvalComparison,\n EvalCompareOptions,\n EvalRegression,\n EvalImprovement,\n} from './types.js';\nimport { pairedBootstrapCI } from './bootstrap.js';\nimport { scorerCounts, evaluateScorerTolerance, round } from './utils.js';\n\nconst DEFAULT_LLM_THRESHOLD = 0.05;\nconst DEFAULT_DETERMINISTIC_THRESHOLD = 0;\nconst LEGACY_THRESHOLD = 0.1;\n\nfunction resolveThreshold(\n scorerName: string,\n options: EvalCompareOptions | undefined,\n metadata: Record<string, unknown>,\n): number {\n // Explicit global threshold\n if (typeof options?.thresholds === 'number') return options.thresholds;\n\n // Per-scorer threshold map\n if (options?.thresholds && typeof options.thresholds === 'object') {\n const perScorer = options.thresholds[scorerName];\n if (perScorer != null) return perScorer;\n // Fall through to auto-calibration if scorer not in map\n }\n\n // Auto-calibrate from scorerTypes metadata\n const scorerTypes = metadata.scorerTypes as Record<string, string> | undefined;\n if (scorerTypes && scorerName in scorerTypes) {\n return scorerTypes[scorerName] === 'llm'\n ? DEFAULT_LLM_THRESHOLD\n : DEFAULT_DETERMINISTIC_THRESHOLD;\n }\n\n // Legacy fallback for results without scorerTypes\n return LEGACY_THRESHOLD;\n}\n\nexport function evalCompare(\n baseline: EvalResult | EvalResult[],\n candidate: EvalResult | EvalResult[],\n options?: EvalCompareOptions,\n): EvalComparison {\n const baselineRunsRaw = Array.isArray(baseline) ? baseline : [baseline];\n const candidateRunsRaw = Array.isArray(candidate) ? candidate : [candidate];\n\n if (baselineRunsRaw.length === 0 || candidateRunsRaw.length === 0) {\n throw new Error('Cannot compare empty eval result arrays');\n }\n\n // Truncate both sides to a common run count BEFORE computing anything. The\n // paired bootstrap CI was already restricted to `min(baseline, candidate)`\n // runs (a CI over paired diffs requires equal-length sides), but means /\n // regressions / timing / cost previously used the full-length pool on each\n // side. That hybrid produced an internally inconsistent view: a 5-run\n // baseline vs 2-run candidate showed `delta = mean(5) - mean(2)` next to\n // a CI computed over only 2 paired diffs, so the user couldn't tell the\n // numbers were drawn from different samples. Truncating symmetrically\n // here keeps every per-scorer figure aligned with the CI's sample size,\n // and the `runCount` field on each side surfaces the truncation\n // explicitly so the UI can render \"n=2 of 5 pooled\".\n const runCount = Math.min(baselineRunsRaw.length, candidateRunsRaw.length);\n const baselineRuns = baselineRunsRaw.slice(0, runCount);\n const candidateRuns = candidateRunsRaw.slice(0, runCount);\n\n // Use the first run as representative for metadata, dataset, scorers.\n // `partial` detection downstream still walks the FULL pool so\n // pre-truncation history (`metadata.batchAttempted` from any pooled run)\n // is honored.\n const baselineRef = baselineRunsRaw[0];\n const candidateRef = candidateRunsRaw[0];\n\n if (baselineRef.dataset !== candidateRef.dataset) {\n throw new Error(\n `Cannot compare evals from different datasets: \"${baselineRef.dataset}\" vs \"${candidateRef.dataset}\"`,\n );\n }\n\n const baselineScorerNames = Object.keys(baselineRef.summary.scorers).sort();\n const candidateScorerNames = Object.keys(candidateRef.summary.scorers).sort();\n if (JSON.stringify(baselineScorerNames) !== JSON.stringify(candidateScorerNames)) {\n throw new Error(`Cannot compare evals with different scorers`);\n }\n\n // Collect per-item paired differences for each scorer across all runs (used for bootstrap CI).\n // For multi-run: pool differences from all (baselineRun[r].items[i], candidateRun[r].items[i]) pairs.\n const pairedDiffs: Record<string, number[]> = {};\n for (const name of baselineScorerNames) {\n pairedDiffs[name] = [];\n }\n for (let r = 0; r < runCount; r++) {\n const bRun = baselineRuns[r];\n const cRun = candidateRuns[r];\n const minLength = Math.min(bRun.items.length, cRun.items.length);\n for (let i = 0; i < minLength; i++) {\n const bItem = bRun.items[i];\n const cItem = cRun.items[i];\n if (bItem.error || cItem.error) continue;\n for (const name of baselineScorerNames) {\n const bScore = bItem.scores[name];\n const cScore = cItem.scores[name];\n if (bScore != null && cScore != null) {\n pairedDiffs[name].push(cScore - bScore);\n }\n }\n }\n }\n\n // Compute aggregate means across the truncated runs (matches the CI's sample).\n const baselineMeans: Record<string, number> = {};\n const candidateMeans: Record<string, number> = {};\n for (const name of baselineScorerNames) {\n baselineMeans[name] =\n baselineRuns.reduce((sum, r) => sum + (r.summary.scorers[name]?.mean ?? 0), 0) /\n baselineRuns.length;\n candidateMeans[name] =\n candidateRuns.reduce((sum, r) => sum + (r.summary.scorers[name]?.mean ?? 0), 0) /\n candidateRuns.length;\n }\n\n const scorers: EvalComparison['scorers'] = {};\n for (const name of baselineScorerNames) {\n const bMeanRaw = baselineMeans[name];\n const cMeanRaw = candidateMeans[name];\n const deltaRaw = cMeanRaw - bMeanRaw;\n const bMean = round(bMeanRaw);\n const cMean = round(cMeanRaw);\n const delta = round(deltaRaw);\n const deltaPercent = bMeanRaw > 0 ? round((deltaRaw / bMeanRaw) * 100) : 0;\n const threshold = resolveThreshold(name, options, baselineRef.metadata);\n\n // Per-side scored/failed over the SAME truncated pool the means/CI use, so\n // a gate (`--max-scorer-error-rate`) reads a sample consistent with the\n // displayed numbers. Sum across this side's truncated runs (the\n // `scorerCounts` helper excludes workflow-errored items and counts a\n // ran-and-failed scorer via its `scoreDetails.duration` discriminator).\n let baselineScored = 0;\n let baselineFailed = 0;\n let baselineSkipped = 0;\n for (const run of baselineRuns) {\n const c = scorerCounts(run.items, name);\n baselineScored += c.scored;\n baselineFailed += c.failed;\n baselineSkipped += c.skipped;\n }\n let candidateScored = 0;\n let candidateFailed = 0;\n let candidateSkipped = 0;\n for (const run of candidateRuns) {\n const c = scorerCounts(run.items, name);\n candidateScored += c.scored;\n candidateFailed += c.failed;\n candidateSkipped += c.skipped;\n }\n\n const entry: EvalComparison['scorers'][string] = {\n baselineMean: bMean,\n candidateMean: cMean,\n delta,\n deltaPercent,\n baselineScored,\n baselineFailed,\n candidateScored,\n candidateFailed,\n baselineSkipped,\n candidateSkipped,\n };\n\n // `n` is the PAIRED sample size — items scored on BOTH sides, the only\n // items a difference can be computed for. Always set it (even 0/1), because\n // that's exactly the asymmetric case the labeling needs to surface: the\n // displayed `delta` is built from each side's INDEPENDENT mean (over that\n // side's own scored items), while the CI below is paired. When `n` is small\n // relative to `{baseline,candidate}Scored`, the two rest on different\n // samples. The CI/significance machinery still requires >= 2 paired diffs.\n const diffs = pairedDiffs[name];\n entry.n = diffs.length;\n if (diffs.length >= 2) {\n const ci = pairedBootstrapCI(diffs);\n entry.ci = { lower: ci.lower, upper: ci.upper };\n entry.pRegression = ci.pRegression;\n entry.pImprovement = ci.pImprovement;\n // Significant when CI excludes zero AND delta exceeds practical threshold\n const ciExcludesZero = ci.lower > 0 || ci.upper < 0;\n entry.significant = ciExcludesZero && Math.abs(ci.mean) >= threshold;\n }\n\n scorers[name] = entry;\n }\n\n // Per-item regressions/improvements.\n // For multi-run: average each item's score across runs to get a stable per-item comparison.\n const regressions: EvalRegression[] = [];\n const improvements: EvalImprovement[] = [];\n\n const itemCount = Math.min(\n ...baselineRuns.map((r) => r.items.length),\n ...candidateRuns.map((r) => r.items.length),\n );\n\n for (let i = 0; i < itemCount; i++) {\n // Check if any run has an error for this item\n const hasBaselineError = baselineRuns.some((r) => r.items[i]?.error);\n const hasCandidateError = candidateRuns.some((r) => r.items[i]?.error);\n if (hasBaselineError || hasCandidateError) continue;\n\n for (const name of baselineScorerNames) {\n // Average this item's score across all runs on each side\n const bScores = baselineRuns\n .map((r) => r.items[i]?.scores[name])\n .filter((s): s is number => s != null);\n const cScores = candidateRuns\n .map((r) => r.items[i]?.scores[name])\n .filter((s): s is number => s != null);\n if (bScores.length === 0 || cScores.length === 0) continue;\n\n const bAvg = bScores.reduce((a, b) => a + b, 0) / bScores.length;\n const cAvg = cScores.reduce((a, b) => a + b, 0) / cScores.length;\n const delta = round(cAvg - bAvg);\n const threshold = resolveThreshold(name, options, baselineRef.metadata);\n if (delta < -threshold)\n regressions.push({\n itemIndex: i,\n input: baselineRef.items[i]?.input,\n scorer: name,\n baselineScore: round(bAvg),\n candidateScore: round(cAvg),\n delta,\n });\n else if (delta > threshold)\n improvements.push({\n itemIndex: i,\n input: baselineRef.items[i]?.input,\n scorer: name,\n baselineScore: round(bAvg),\n candidateScore: round(cAvg),\n delta,\n });\n }\n }\n\n // Timing comparison (average across all runs for multi-run)\n let timing: EvalComparison['timing'];\n const baselineTimings = baselineRuns\n .filter((r) => r.summary.timing)\n .map((r) => r.summary.timing!.mean);\n const candidateTimings = candidateRuns\n .filter((r) => r.summary.timing)\n .map((r) => r.summary.timing!.mean);\n if (baselineTimings.length > 0 && candidateTimings.length > 0) {\n const bMean = baselineTimings.reduce((a, b) => a + b, 0) / baselineTimings.length;\n const cMean = candidateTimings.reduce((a, b) => a + b, 0) / candidateTimings.length;\n const delta = round(cMean - bMean);\n const deltaPercent = bMean > 0 ? round(((cMean - bMean) / bMean) * 100) : 0;\n timing = { baselineMean: round(bMean), candidateMean: round(cMean), delta, deltaPercent };\n }\n\n // Cost comparison (per-run average for multi-run)\n let cost: EvalComparison['cost'];\n const baselineAvgCost =\n baselineRuns.reduce((sum, r) => sum + r.totalCost, 0) / baselineRuns.length;\n const candidateAvgCost =\n candidateRuns.reduce((sum, r) => sum + r.totalCost, 0) / candidateRuns.length;\n if (baselineAvgCost > 0 || candidateAvgCost > 0) {\n const deltaRaw = candidateAvgCost - baselineAvgCost;\n const delta = round(deltaRaw);\n const deltaPercent = baselineAvgCost > 0 ? round((deltaRaw / baselineAvgCost) * 100) : 0;\n cost = {\n baselineTotal: round(baselineAvgCost),\n candidateTotal: round(candidateAvgCost),\n delta,\n deltaPercent,\n };\n }\n\n const parts: string[] = [];\n for (const name of baselineScorerNames) {\n const s = scorers[name];\n if (Math.abs(s.delta) > 0.001) {\n const direction = s.delta > 0 ? 'improves' : 'regresses';\n const sign = s.delta > 0 ? '+' : '';\n let sigLabel = '';\n if (s.significant === true) sigLabel = ' (significant)';\n else if (s.significant === false) sigLabel = ' (not significant)';\n parts.push(\n `'${name}' ${direction} by ${sign}${s.deltaPercent.toFixed(1)}% (${s.baselineMean.toFixed(2)} -> ${s.candidateMean.toFixed(2)})${sigLabel}`,\n );\n }\n }\n if (timing && Math.abs(timing.deltaPercent) > 1) {\n const dir = timing.delta > 0 ? 'slower' : 'faster';\n parts.push(`${Math.abs(timing.deltaPercent).toFixed(0)}% ${dir}`);\n }\n if (cost && Math.abs(cost.deltaPercent) > 1) {\n const dir = cost.delta > 0 ? 'more expensive' : 'cheaper';\n parts.push(`${Math.abs(cost.deltaPercent).toFixed(0)}% ${dir}`);\n }\n const summaryStr = `candidate ${parts.length > 0 ? parts.join(', ') : 'no meaningful changes'} with ${regressions.length} regressions and ${improvements.length} improvements`;\n\n // Run partial detection against the FULL pre-truncation pool. The user's\n // original selection (e.g. 5 of an attempted 10 runs) determines partial\n // status; the truncation we did above is a stats-consistency concern, not\n // a partial-batch one.\n const baselinePartial = detectPartial(baselineRunsRaw);\n const candidatePartial = detectPartial(candidateRunsRaw);\n\n return {\n baseline: {\n id: baselineRef.id,\n metadata: baselineRef.metadata,\n runCount,\n ...(baselinePartial ? { partial: baselinePartial } : {}),\n },\n candidate: {\n id: candidateRef.id,\n metadata: candidateRef.metadata,\n runCount,\n ...(candidatePartial ? { partial: candidatePartial } : {}),\n },\n scorers,\n timing,\n cost,\n regressions,\n improvements,\n summary: summaryStr,\n };\n}\n\n/**\n * Detect whether one side of a comparison was pooled from a partial batch\n * (or a user-selected subset). Returns `{ completed, attempted }` when the\n * pooled run count is less than the original batch's planned run count\n * (read from `metadata.batchAttempted` on any run in the pool); `undefined`\n * otherwise.\n *\n * The signal is the same regardless of cause (batch failed mid-way vs user\n * cherry-picked from the picker) — both result in a smaller-N pool that\n * the consumer should mark visually so the comparison isn't mistaken for\n * an apples-to-apples run.\n *\n * Walks every run looking for the first finite `batchAttempted` rather than\n * trusting `runs[0]` alone — when a user cherry-picks runs from the compare\n * picker, the array order is the user's order, so the first item may be a\n * legacy single-run with no batch metadata while a sibling carries it.\n *\n * If `runs.length > attempted` (more results than were planned), treats the\n * data as suspicious and returns `undefined` — silently marking it \"complete\"\n * would mask data corruption.\n */\nfunction detectPartial(runs: EvalResult[]): { completed: number; attempted: number } | undefined {\n if (runs.length === 0) return undefined;\n let attempted: number | undefined;\n for (const r of runs) {\n const v = r.metadata?.batchAttempted;\n if (typeof v === 'number' && Number.isFinite(v)) {\n attempted = v;\n break;\n }\n }\n if (attempted === undefined) return undefined;\n if (runs.length >= attempted) return undefined;\n return { completed: runs.length, attempted };\n}\n\n/**\n * Decide whether a comparison should be REFUSED under a gate-side scorer\n * failure-rate limit (`axl-eval compare --max-scorer-error-rate`). Pure and\n * testable — returns a human-readable refusal reason, or `null` to allow.\n *\n * Type-aware via the baseline's `scorerTypes` metadata: a scorer EXPLICITLY\n * marked `'deterministic'` tolerates ZERO failures (a deterministic throw is a\n * bug); everything else — including an unknown/absent type on a pre-`scorerTypes`\n * artifact — uses the LLM `limit`. Defaulting unknown types to LLM (the\n * permissive tier) is deliberate: classifying an old artifact's scorers as\n * deterministic would hard-fail them on the first flake, contradicting the\n * `--max-scorer-error-rate <n>` the user passed. Scorer NAMES are identical\n * across sides (enforced by `evalCompare`), so reading types from the baseline\n * is sufficient.\n *\n * Also refuses a scorer that produced ZERO scored items on a side — a mean over\n * an empty sample can't be certified. Counts come from the same truncated pool\n * `evalCompare` used for the means/CI (`baseline/candidateScored/Failed`).\n */\nexport function evaluateScorerErrorRateGate(\n comparison: EvalComparison,\n maxScorerErrorRate: number,\n): string | null {\n const scorerTypes = (comparison.baseline.metadata?.scorerTypes ?? {}) as Record<string, string>;\n for (const name of Object.keys(comparison.scorers)) {\n const s = comparison.scorers[name];\n const type = scorerTypes[name] === 'deterministic' ? 'deterministic' : 'llm';\n const limit = type === 'deterministic' ? 0 : maxScorerErrorRate;\n for (const side of ['baseline', 'candidate'] as const) {\n const scored = (side === 'baseline' ? s.baselineScored : s.candidateScored) ?? 0;\n const failed = (side === 'baseline' ? s.baselineFailed : s.candidateFailed) ?? 0;\n const skipped = (side === 'baseline' ? s.baselineSkipped : s.candidateSkipped) ?? 0;\n const verdict = evaluateScorerTolerance(scored, failed, type, limit);\n if (verdict.zeroSample) {\n // attempted === 0 means the scorer produced no valid scores AND recorded\n // no ran-and-failed attempts on this side, so a mean over an empty sample\n // can't be certified. Distinguish the likely cause: a fully `applies`-\n // skipped scorer (N/A on every item — a scope/config issue, not a fault)\n // vs. items that errored in the workflow.\n const cause =\n skipped > 0\n ? `every one of its items was N/A (the \\`applies\\` predicate skipped all ${skipped})`\n : `its items errored or produced no score`;\n return `scorer \"${name}\" has no scored items on ${side} (${cause}) — cannot certify a mean over an empty sample.`;\n }\n if (verdict.exceeds) {\n const limitStr =\n type === 'deterministic'\n ? 'deterministic zero-tolerance'\n : `${(limit * 100).toFixed(1)}%`;\n return `scorer \"${name}\" failed ${(verdict.rate * 100).toFixed(1)}% on ${side} (${failed}/${verdict.attempted}), over the ${limitStr} limit.`;\n }\n }\n }\n return null;\n}\n","import type { Provider } from '@axlsdk/axl';\n\n/** Result from a scorer that includes metadata beyond the numeric score. */\nexport type ScorerResult = {\n score: number;\n metadata?: Record<string, unknown>;\n cost?: number;\n};\n\n/** Normalize a scorer return value to a ScorerResult. */\nexport function normalizeScorerResult(result: number | ScorerResult): ScorerResult {\n return typeof result === 'number' ? { score: result } : result;\n}\n\n/**\n * Cost contract for thrown scorer errors. A scorer (e.g. `llmScorer`) that\n * incurs provider cost *before* failing attaches that cost to the thrown error\n * via {@link attachScorerErrorCost} so the eval runner still bills it. The\n * cost rides as an enumerable `cost` property (a small, stable public contract\n * custom scorers can also use). These helpers replace scattered `(err as any).cost`\n * reads/writes with one typed, finite-guarded surface.\n */\nexport function attachScorerErrorCost(err: unknown, cost: number | undefined): void {\n if (\n err &&\n typeof err === 'object' &&\n typeof cost === 'number' &&\n Number.isFinite(cost) &&\n cost >= 0\n ) {\n (err as { cost?: number }).cost = cost;\n }\n}\n\n/** Read a non-negative finite cost off a thrown scorer error, or `undefined`. */\nexport function extractScorerErrorCost(err: unknown): number | undefined {\n const v = err && typeof err === 'object' ? (err as { cost?: unknown }).cost : undefined;\n return typeof v === 'number' && Number.isFinite(v) && v >= 0 ? v : undefined;\n}\n\n/** Context passed to scorers by the eval runner. */\nexport type ScorerContext = {\n /** Resolve a provider:model URI to a provider instance and model name. */\n resolveProvider: (modelUri: string) => { provider: Provider; model: string };\n /** Abort signal forwarded from the eval runner; scorers should pass it into provider calls. */\n signal?: AbortSignal;\n};\n\nexport type ScorerFn<TOutput, TInput, TAnnotations> = (\n output: TOutput,\n input: TInput,\n annotations?: TAnnotations,\n) => number | ScorerResult;\n\n/**\n * Applicability predicate for a conditional scorer. Returns `true` if this\n * scorer should run for the given item, `false` to skip it.\n *\n * The eval runner runs every scorer against every item, so a scorer that only\n * applies to a subset (a refusal judge for refusal-expected items, a constraint\n * judge for constrained items, …) declares its scope here. A skipped item is\n * counted as NEITHER `scored` NOR `failed` — it's excluded from the mean AND\n * from the failure-rate denominator, so a conditional scorer stays honest to\n * both. The predicate runs BEFORE the scorer body, so an inapplicable\n * `llmScorer` never makes its provider call.\n *\n * Signature mirrors {@link ScorerFn} (`output, input, annotations`). Applicability\n * usually keys off `input`/`annotations` (e.g. a flag or exercise type), but\n * `output` is available too (e.g. \"only score outputs that refused\"). A\n * predicate that THROWS is a bug, not a skip — it's recorded as a scorer\n * failure, never silently swallowed.\n *\n * The contract is `=> boolean`: return `true` to run, `false` to skip. The\n * runtime is defensively lenient — it coerces with `!verdict`, so a stray falsy\n * value (a predicate that forgot to `return`) skips rather than crashes — but\n * authors should return a real boolean. When deriving from a truthy value,\n * coerce it yourself: `(o, i, a) => !!a.constraints?.length`, not\n * `=> a.constraints?.length` (which is `number | undefined`, a type error). A\n * predicate that accidentally never returns therefore skips EVERY item — but\n * that surfaces conspicuously as a non-zero `skipped` count (the Studio \"N/A\"\n * chip), not as a silently green mean.\n */\nexport type ScorerApplies<TOutput, TInput, TAnnotations> = (\n output: TOutput,\n input: TInput,\n annotations?: TAnnotations,\n) => boolean;\n\nexport type ScorerConfig<TOutput = unknown, TInput = unknown, TAnnotations = unknown> = {\n name: string;\n description: string;\n score: ScorerFn<TOutput, TInput, TAnnotations>;\n /** Optional applicability predicate — see {@link ScorerApplies}. When it\n * returns `false`, the scorer is skipped for that item (counted as neither\n * scored nor failed). Omit to run on every item (the default).\n *\n * Declared with **method syntax** (not a function-valued property) for parity\n * with {@link Scorer.applies}, where the syntax is load-bearing: see the note\n * there and `__tests__/scorer-assignability.test-d.ts`. */\n applies?(output: TOutput, input: TInput, annotations?: TAnnotations): boolean;\n};\n\nexport type Scorer<TOutput = unknown, TInput = unknown, TAnnotations = unknown> = {\n readonly name: string;\n readonly description: string;\n readonly isLlm: boolean;\n score(\n output: TOutput,\n input: TInput,\n annotations?: TAnnotations,\n context?: ScorerContext,\n ): number | ScorerResult | Promise<number | ScorerResult>;\n /** See {@link ScorerApplies}. Evaluated by the runner before {@link score}.\n *\n * Declared with **method syntax** (not a function-valued `ScorerApplies`\n * property) so its parameters are checked bivariantly, exactly like\n * {@link score}. `EvalConfig.scorers` erases the generics to\n * `Scorer<unknown, unknown, unknown>[]`; under `strictFunctionTypes` a\n * property would make those params contravariant, so a concretely-typed\n * `Scorer<…, TInput, TAnnotations>` would no longer be assignable to that\n * array (the 0.18.1 regression). `__tests__/scorer-assignability.test-d.ts`\n * locks this in and is compiled by the `typecheck` gate. */\n applies?(output: TOutput, input: TInput, annotations?: TAnnotations): boolean;\n};\n\nexport function scorer<TOutput = unknown, TInput = unknown, TAnnotations = unknown>(\n config: ScorerConfig<TOutput, TInput, TAnnotations>,\n): Scorer<TOutput, TInput, TAnnotations> {\n return {\n name: config.name,\n description: config.description,\n isLlm: false,\n score: config.score,\n applies: config.applies,\n };\n}\n","import type { Scorer, ScorerContext } from './scorer.js';\nimport { normalizeScorerResult, extractScorerErrorCost } from './scorer.js';\nimport type { EvalItem } from './types.js';\nimport { round, mapWithConcurrency } from './utils.js';\n\n/** The subset of an `EvalItem` that `scoreItem` reads and mutates. */\ntype ScorableItem = Pick<\n EvalItem,\n 'input' | 'output' | 'annotations' | 'scores' | 'scoreDetails' | 'scorerErrors' | 'scorerCost'\n>;\n\n/**\n * Score one item's `output` with every scorer in `scorers`, running up to\n * `scorerConcurrency` of them at once. Mutates `item.scores`,\n * `item.scoreDetails`, `item.scorerErrors`, and `item.scorerCost` in place, and\n * returns the per-item scorer cost so the caller can fold it into its own\n * running total (`totalCost += await scoreItem(...)`).\n *\n * This is the single source of truth for the scoring inner loop, shared by\n * `runEval` and `rescore` — both previously carried a byte-identical copy, so a\n * determinism or cancellation fix had to be made twice.\n *\n * Determinism (independent of scorer completion order):\n * - `scores`/`scoreDetails` keys are pre-seeded in `scorers` order, so JSON key\n * order is stable and a scorer skipped by cancellation is deterministically\n * `null` rather than absent.\n * - `scorerErrors` are collected name-keyed and flattened in `scorers` order.\n *\n * Cancellation: a scorer not yet started when `signal` aborts is skipped; an\n * in-flight scorer whose call rejects with an `AbortError` is treated as\n * cancellation (leaves its pre-seeded `null`, records no error) — narrowed to\n * the error identity so a genuine bug in another scorer that happens to throw\n * while a sibling triggered the abort is still reported, not swallowed.\n */\nexport async function scoreItem(\n item: ScorableItem,\n scorers: readonly Scorer<unknown, unknown, unknown>[],\n scorerConcurrency: number,\n scorerContext: ScorerContext,\n signal?: AbortSignal,\n): Promise<number> {\n const scoreDetails = (item.scoreDetails ??= {});\n for (const s of scorers) {\n item.scores[s.name] = null;\n scoreDetails[s.name] = { score: null };\n }\n\n let itemScorerCost = 0;\n const scorerErrorsByName: Record<string, string> = {};\n\n await mapWithConcurrency(scorers, scorerConcurrency, async (scorer) => {\n if (signal?.aborted) return;\n const scorerStart = Date.now();\n try {\n // Applicability gate: a conditional scorer declares which items it applies\n // to via `applies`. A `false` verdict skips it entirely — no provider call\n // for an llmScorer — and records it as NEITHER scored nor failed via the\n // positive `skipped` marker (no `duration`, so the duration heuristic in\n // `scorerCounts` can't misread it as a failure). A predicate that THROWS is\n // a bug, not a skip: it falls through to the catch below and is recorded as\n // a scorer failure (with a duration), never silently swallowed.\n if (scorer.applies && !scorer.applies(item.output, item.input, item.annotations)) {\n item.scores[scorer.name] = null;\n scoreDetails[scorer.name] = { score: null, skipped: true };\n return;\n }\n\n const raw = await scorer.score(item.output, item.input, item.annotations, scorerContext);\n const scorerResult = normalizeScorerResult(raw);\n\n if (scorerResult.cost != null) {\n itemScorerCost += scorerResult.cost;\n }\n\n const scorerDuration = Date.now() - scorerStart;\n\n if (\n !Number.isFinite(scorerResult.score) ||\n scorerResult.score < 0 ||\n scorerResult.score > 1\n ) {\n scorerErrorsByName[scorer.name] =\n `Scorer \"${scorer.name}\" returned out-of-range score ${scorerResult.score} for input ${JSON.stringify(item.input)}`;\n item.scores[scorer.name] = null;\n scoreDetails[scorer.name] = {\n score: null,\n metadata: scorerResult.metadata,\n duration: scorerDuration,\n cost: scorerResult.cost,\n };\n } else {\n item.scores[scorer.name] = round(scorerResult.score);\n scoreDetails[scorer.name] = {\n score: round(scorerResult.score),\n metadata: scorerResult.metadata,\n duration: scorerDuration,\n cost: scorerResult.cost,\n };\n }\n } catch (err) {\n // A cancelled call (AbortError) is not a scoring failure — leave the\n // pre-seeded null and record nothing.\n if ((err as { name?: string })?.name === 'AbortError') return;\n const errCost = extractScorerErrorCost(err);\n if (errCost != null) itemScorerCost += errCost;\n scorerErrorsByName[scorer.name] =\n `Scorer \"${scorer.name}\" threw: ${err instanceof Error ? err.message : String(err)}`;\n item.scores[scorer.name] = null;\n scoreDetails[scorer.name] = {\n score: null,\n duration: Date.now() - scorerStart,\n cost: errCost,\n };\n }\n });\n\n const orderedErrors = scorers\n .map((s) => scorerErrorsByName[s.name])\n .filter((e): e is string => e != null);\n if (orderedErrors.length > 0) item.scorerErrors = orderedErrors;\n item.scorerCost = itemScorerCost > 0 ? itemScorerCost : undefined;\n return itemScorerCost;\n}\n","import type { AxlRuntime } from '@axlsdk/axl';\nimport type { EvalConfig, EvalResult, EvalItem, EvalSummary, RunEvalOptions } from './types.js';\nimport type { ScorerContext } from './scorer.js';\nimport type { DegradedScorer } from './types.js';\nimport {\n computeStats,\n mapWithConcurrency,\n scorerCounts,\n evaluateScorerTolerance,\n} from './utils.js';\nimport { scoreItem } from './score-item.js';\nimport { randomUUID } from 'node:crypto';\n\nfunction parseCost(cost: string): number {\n const match = cost.match(/^\\$?([\\d.]+)$/);\n if (!match) throw new Error(`Invalid cost format: \"${cost}\"`);\n return parseFloat(match[1]);\n}\n\n/**\n * Extract a user-returned cost only if it's a non-negative finite number.\n * Guards against workflows that return `{ cost: 'free' }`, `{ cost: NaN }`,\n * `{ cost: -1 }`, `{ cost: Infinity }`, etc. — the TS type says `cost?: number`\n * but at runtime we can't trust that.\n *\n * Negative costs are rejected because (a) cost is a USD amount and negative\n * values are nonsensical, and (b) a negative cost would silently shrink\n * `totalCost` below the budget limit check at the processItem level,\n * letting a buggy/malicious workflow run unbounded. `0` is preserved\n * because free operations on paid models are valid.\n *\n * When a user-supplied value is rejected (present but invalid), we log\n * once per item via `console.warn` so the type violation is visible\n * rather than silently swallowed.\n */\nfunction extractUserCost(result: unknown, label = 'executeWorkflow'): number | undefined {\n if (result === null || typeof result !== 'object') return undefined;\n const raw = (result as { cost?: unknown }).cost;\n if (raw === undefined) return undefined;\n if (typeof raw === 'number' && Number.isFinite(raw) && raw >= 0) return raw;\n\n console.warn(\n `[axl-eval] Ignoring invalid \\`cost\\` from ${label} return: expected non-negative finite number, got ${typeof raw === 'number' ? String(raw) : typeof raw}. Falling back to tracked cost (or undefined).`,\n );\n return undefined;\n}\n\n/**\n * Extract a user-returned metadata record only if it's a plain object.\n * Rejects arrays, null, scalars, and exotic object types (Date, Map, Set,\n * Error, class instances) that would satisfy a loose `typeof === 'object'`\n * check but break `Record<string, unknown>` assumptions in downstream\n * consumers (spread, Object.entries, property access).\n */\nfunction extractUserMetadata(\n result: unknown,\n label = 'executeWorkflow',\n): Record<string, unknown> | undefined {\n if (result === null || typeof result !== 'object') return undefined;\n const meta = (result as { metadata?: unknown }).metadata;\n if (meta === undefined) return undefined;\n if (meta === null || typeof meta !== 'object' || Array.isArray(meta)) {\n console.warn(\n `[axl-eval] Ignoring invalid \\`metadata\\` from ${label} return: expected plain object, got ${meta === null ? 'null' : Array.isArray(meta) ? 'array' : typeof meta}.`,\n );\n return undefined;\n }\n // Reject exotic objects (Date, Map, Set, Error, class instances) whose\n // prototype chain differs from Object.prototype. Those pass `typeof ===\n // 'object'` but don't behave like `Record<string, unknown>`.\n const proto = Object.getPrototypeOf(meta);\n if (proto !== Object.prototype && proto !== null) {\n console.warn(\n `[axl-eval] Ignoring invalid \\`metadata\\` from ${label} return: expected plain object, got ${(proto?.constructor?.name as string | undefined) ?? 'exotic object'}.`,\n );\n return undefined;\n }\n return meta as Record<string, unknown>;\n}\n\nexport async function runEval(\n config: EvalConfig,\n executeWorkflow: (\n input: unknown,\n runtime: AxlRuntime,\n ) => Promise<{ output: unknown; cost?: number; metadata?: Record<string, unknown> }>,\n runtime: AxlRuntime,\n options?: RunEvalOptions,\n): Promise<EvalResult> {\n const startTime = Date.now();\n const id = randomUUID();\n const items = await config.dataset.getItems();\n // Snapshot dataset-load diagnostics (e.g. annotation keys the schema dropped)\n // so we can surface them on EvalResult.metadata for any consumer — mirrors the\n // console.warn the dataset already emits. Read synchronously after getItems()\n // (no await between); defensive against hand-rolled Dataset objects that don't\n // expose the field.\n const droppedAnnotationKeys = [...(config.dataset.droppedAnnotationKeys ?? [])];\n const concurrency = config.concurrency ?? 5;\n // Per-item scorer fan-out. Defaults to the same value as item `concurrency`\n // (parallel-by-default), so the worst-case concurrent judge calls is\n // `concurrency × scorerConcurrency`. The provider layer backs off on\n // 429/503/529; users who need a tighter ceiling lower item `concurrency`.\n const scorerConcurrency = config.scorerConcurrency ?? 5;\n const budgetLimit = config.budget ? parseCost(config.budget) : undefined;\n\n // Create a scorer context that LLM scorers use to resolve providers.\n const scorerContext: ScorerContext = {\n resolveProvider: (uri: string) => {\n if (typeof runtime.resolveProvider !== 'function') {\n throw new Error(\n `LLM scorers require a runtime with resolveProvider(). ` +\n `Ensure you are using a real AxlRuntime instance, not a mock.`,\n );\n }\n return runtime.resolveProvider(uri);\n },\n signal: options?.signal,\n };\n\n const evalItems: EvalItem[] = new Array(items.length);\n let totalCost = 0;\n let budgetExceeded = false;\n\n async function processItem(item: (typeof items)[0], itemIndex: number): Promise<void> {\n if (options?.signal?.aborted) {\n evalItems[itemIndex] = {\n input: item.input,\n annotations: item.annotations,\n output: null,\n error: 'Cancelled',\n scores: {},\n };\n options?.onProgress?.({ type: 'item_done', itemIndex, totalItems: items.length });\n return;\n }\n\n if (budgetExceeded) {\n evalItems[itemIndex] = {\n input: item.input,\n annotations: item.annotations,\n output: null,\n error: 'Budget exceeded',\n scores: {},\n };\n options?.onProgress?.({ type: 'item_done', itemIndex, totalItems: items.length });\n return;\n }\n\n const evalItem: EvalItem = {\n input: item.input,\n annotations: item.annotations,\n output: null,\n scores: {},\n };\n const itemStart = Date.now();\n try {\n // When captureTraces is on, wrap the user's executeWorkflow in\n // trackExecution so we get a per-item TraceEvent[] scoped via\n // AsyncLocalStorage. trackExecution's scope walks the parent chain, so\n // any nested trackExecution (e.g. from the CLI) continues to work.\n if (options?.captureTraces) {\n const tracked = await runtime.trackExecution(\n async () => executeWorkflow(item.input, runtime),\n { captureTraces: true },\n );\n evalItem.duration = Date.now() - itemStart;\n evalItem.output = tracked.result.output;\n // Prefer user-returned cost/metadata; fall back to tracked values.\n // Type-guarded so a non-number cost (e.g. `{ cost: 'free' }`) or a\n // non-object metadata (e.g. an array or scalar) doesn't silently\n // corrupt downstream math or shape expectations.\n evalItem.cost = extractUserCost(tracked.result) ?? tracked.cost;\n if (tracked.unpriced) evalItem.unpriced = true;\n evalItem.metadata = extractUserMetadata(tracked.result) ?? tracked.metadata;\n if (tracked.traces && tracked.traces.length > 0) {\n evalItem.traces = tracked.traces;\n }\n if (evalItem.cost != null) {\n totalCost += evalItem.cost;\n }\n } else {\n const result = await executeWorkflow(item.input, runtime);\n evalItem.duration = Date.now() - itemStart;\n evalItem.output = result.output;\n evalItem.cost = extractUserCost(result);\n const meta = extractUserMetadata(result);\n if (meta) evalItem.metadata = meta;\n if (evalItem.cost != null) {\n totalCost += evalItem.cost;\n }\n }\n } catch (err) {\n evalItem.duration = Date.now() - itemStart;\n evalItem.error = err instanceof Error ? err.message : String(err);\n // Failed items are exactly when per-item traces are most valuable —\n // recover them from the captured-traces side-channel `trackExecution`\n // attaches to the error on the failure path.\n if (options?.captureTraces) {\n const captured = (err as { axlCapturedTraces?: unknown }).axlCapturedTraces;\n if (Array.isArray(captured) && captured.length > 0) {\n evalItem.traces = captured as EvalItem['traces'];\n }\n }\n evalItems[itemIndex] = evalItem;\n options?.onProgress?.({ type: 'item_done', itemIndex, totalItems: items.length });\n return;\n }\n\n if (budgetLimit != null && totalCost > budgetLimit) {\n budgetExceeded = true;\n }\n\n // Score the item's output with all scorers (bounded fan-out). scoreItem\n // owns the determinism + cancellation + cost logic shared with rescore();\n // it returns the per-item scorer cost to fold into the running total.\n // NB: keep the await on its own line — `totalCost += await …` would read\n // totalCost BEFORE suspending, losing updates across concurrent items.\n const itemScorerCost = await scoreItem(\n evalItem,\n config.scorers,\n scorerConcurrency,\n scorerContext,\n options?.signal,\n );\n totalCost += itemScorerCost;\n evalItems[itemIndex] = evalItem;\n options?.onProgress?.({ type: 'item_done', itemIndex, totalItems: items.length });\n }\n\n // processItem writes into the pre-allocated `evalItems` closure array (the\n // source of truth) and returns void — the pool's returned array is ignored.\n await mapWithConcurrency(items, concurrency, (item, i) => processItem(item, i));\n\n const failures = evalItems.filter((i) => i.error).length;\n const scorerNames = config.scorers.map((s) => s.name);\n const scorerStats: EvalSummary['scorers'] = {};\n for (const name of scorerNames) {\n const scores = evalItems\n .filter((i) => !i.error && i.scores[name] != null)\n .map((i) => i.scores[name] as number);\n const { scored, failed, skipped } = scorerCounts(evalItems, name);\n scorerStats[name] = { ...computeStats(scores), scored, failed, skipped };\n }\n\n const scorerTypes: Record<string, string> = {};\n for (const s of config.scorers) {\n scorerTypes[s.name] = s.isLlm ? 'llm' : 'deterministic';\n }\n\n // Failure-rate trust signal (opt-in). When `failOnScorerErrorRate` is set, a\n // scorer is degraded when it's deterministic and failed at all (a failure is\n // a bug, not noise), OR it's an LLM judge whose failure rate over its\n // ATTEMPTED items exceeds tolerance. We never throw — the result is still\n // useful; we flag it and let the CLI/consumer decide the exit code. Invalid\n // limits are ignored loudly so a typo can't silently disable the gate.\n let degraded: DegradedScorer[] | undefined;\n const rawLimit = config.failOnScorerErrorRate;\n if (rawLimit != null) {\n if (!Number.isFinite(rawLimit) || rawLimit < 0 || rawLimit > 1) {\n console.warn(\n `[axl-eval] Ignoring invalid failOnScorerErrorRate (${rawLimit}); expected a number in [0, 1].`,\n );\n } else {\n for (const name of scorerNames) {\n const stats = scorerStats[name];\n const scored = stats.scored ?? 0;\n const failed = stats.failed ?? 0;\n const type = scorerTypes[name] === 'llm' ? 'llm' : 'deterministic';\n const limit = type === 'deterministic' ? 0 : rawLimit;\n const verdict = evaluateScorerTolerance(scored, failed, type, limit);\n // A scorer that never ran (zeroSample) isn't degraded at the source — the\n // run produced no basis to judge it. (The compare gate treats zero-sample\n // differently: it refuses to certify it.)\n if (verdict.exceeds) {\n (degraded ??= []).push({ scorer: name, rate: verdict.rate, limit, type, scored, failed });\n }\n }\n }\n }\n\n const durations = evalItems.filter((i) => !i.error && i.duration != null).map((i) => i.duration!);\n const timing = durations.length > 0 ? computeStats(durations) : undefined;\n\n // Aggregate per-model LLM call counts across all items\n const totalModelCalls = new Map<string, number>();\n for (const item of evalItems) {\n const itemCounts = item.metadata?.modelCallCounts;\n if (itemCounts && typeof itemCounts === 'object') {\n for (const [m, count] of Object.entries(itemCounts as Record<string, unknown>)) {\n if (typeof count === 'number')\n totalModelCalls.set(m, (totalModelCalls.get(m) ?? 0) + count);\n }\n } else {\n // Fallback: count unique models per item (for executeWorkflow that doesn't provide call counts)\n const itemModels = item.metadata?.models;\n if (Array.isArray(itemModels)) {\n for (const m of itemModels) {\n if (typeof m === 'string') totalModelCalls.set(m, (totalModelCalls.get(m) ?? 0) + 1);\n }\n }\n }\n }\n\n // models: unique list sorted by total calls (most-called first)\n // modelCounts: total LLM calls per model (e.g., { \"openai:gpt-4o\": 12, \"openai:gpt-4o-mini\": 12 })\n const modelsMeta: Record<string, unknown> = {};\n if (totalModelCalls.size > 0) {\n const sorted = [...totalModelCalls.entries()].sort((a, b) => b[1] - a[1]);\n modelsMeta.models = sorted.map(([m]) => m);\n modelsMeta.modelCounts = Object.fromEntries(sorted);\n }\n\n // Aggregate per-workflow call counts across all items (parallel to models).\n // Workflows come from trackExecution's trace-event collection — callers\n // don't specify workflow names anywhere, they just appear because the\n // runtime emits workflow_start events for every execute() call.\n const totalWorkflowCalls = new Map<string, number>();\n for (const item of evalItems) {\n const itemCounts = item.metadata?.workflowCallCounts;\n if (itemCounts && typeof itemCounts === 'object') {\n for (const [w, count] of Object.entries(itemCounts as Record<string, unknown>)) {\n if (typeof count === 'number')\n totalWorkflowCalls.set(w, (totalWorkflowCalls.get(w) ?? 0) + count);\n }\n } else {\n // Fallback: count unique workflows per item\n const itemWorkflows = item.metadata?.workflows;\n if (Array.isArray(itemWorkflows)) {\n for (const w of itemWorkflows) {\n if (typeof w === 'string')\n totalWorkflowCalls.set(w, (totalWorkflowCalls.get(w) ?? 0) + 1);\n }\n }\n }\n }\n\n // Fall back to config.workflow when the callback bypassed the runtime's\n // execute() path entirely (e.g. AxlTestRuntime-based tests). This keeps the\n // metadata.workflows array non-empty for the common test-harness case.\n const workflowsMeta: Record<string, unknown> = {};\n if (totalWorkflowCalls.size > 0) {\n const sorted = [...totalWorkflowCalls.entries()].sort((a, b) => b[1] - a[1]);\n workflowsMeta.workflows = sorted.map(([w]) => w);\n workflowsMeta.workflowCounts = Object.fromEntries(sorted);\n } else if (config.workflow) {\n workflowsMeta.workflows = [config.workflow];\n workflowsMeta.workflowCounts = { [config.workflow]: items.length };\n }\n\n options?.onProgress?.({ type: 'run_done', totalItems: items.length, failures });\n\n return {\n id,\n dataset: config.dataset.name,\n metadata: {\n ...config.metadata,\n scorerTypes,\n ...modelsMeta,\n ...workflowsMeta,\n ...(droppedAnnotationKeys.length > 0 ? { droppedAnnotationKeys } : {}),\n },\n timestamp: new Date().toISOString(),\n totalCost,\n ...(evalItems.some((item) => item.unpriced) ? { unpriced: true } : {}),\n duration: Date.now() - startTime,\n items: evalItems,\n summary: {\n count: items.length,\n failures,\n scorers: scorerStats,\n timing,\n ...(degraded ? { degraded } : {}),\n },\n };\n}\n","import type { AxlRuntime } from '@axlsdk/axl';\nimport type { EvalResult, EvalItem, EvalSummary } from './types.js';\nimport type { Scorer, ScorerContext } from './scorer.js';\nimport { computeStats, mapWithConcurrency, scorerCounts } from './utils.js';\nimport { scoreItem } from './score-item.js';\nimport { randomUUID } from 'node:crypto';\n\nexport type RescoreOptions = {\n /** Item-level worker-pool size (how many saved items rescore in parallel). Default 5. */\n concurrency?: number;\n /** Per-item scorer fan-out (how many scorers run concurrently within one item).\n * Default 5 — matches `EvalConfig.scorerConcurrency`. Worst-case concurrent\n * judge calls is `concurrency × scorerConcurrency`. */\n scorerConcurrency?: number;\n /** Abort signal forwarded into ScorerContext so in-flight LLM scorer calls can\n * be cancelled mid-flight. Also checked between items to short-circuit\n * remaining work. Mirrors `RunEvalOptions.signal`. */\n signal?: AbortSignal;\n};\n\n/**\n * Re-run scorers on the saved outputs of an existing eval result.\n * Preserves original input/output/annotations. Only re-runs scoring.\n */\nexport async function rescore(\n result: EvalResult,\n scorers: Scorer[],\n runtime: AxlRuntime,\n options?: RescoreOptions,\n): Promise<EvalResult> {\n const startTime = Date.now();\n const concurrency = options?.concurrency ?? 5;\n const scorerConcurrency = options?.scorerConcurrency ?? 5;\n\n const scorerContext: ScorerContext = {\n resolveProvider: (uri: string) => {\n if (typeof runtime.resolveProvider !== 'function') {\n throw new Error(\n `LLM scorers require a runtime with resolveProvider(). ` +\n `Ensure you are using a real AxlRuntime instance, not a mock.`,\n );\n }\n return runtime.resolveProvider(uri);\n },\n signal: options?.signal,\n };\n\n const rescored: EvalItem[] = new Array(result.items.length);\n let totalCost = 0;\n\n async function rescoreItem(original: EvalItem, itemIndex: number): Promise<void> {\n // Short-circuit if the rescore has been cancelled — matches runEval's\n // between-items signal check (runner.ts) so cancellation behaves the same\n // in both paths. In-flight LLM scorer calls additionally abort via\n // scorerContext.signal → provider.chat({ signal }).\n if (options?.signal?.aborted) {\n rescored[itemIndex] = {\n input: original.input,\n annotations: original.annotations,\n output: original.output,\n error: 'cancelled',\n scores: {},\n };\n return;\n }\n\n // Pass through error items without scoring\n if (original.error) {\n rescored[itemIndex] = {\n input: original.input,\n annotations: original.annotations,\n output: original.output,\n error: original.error,\n scores: {},\n };\n return;\n }\n\n // Preserve per-item traces from the original run: rescore re-runs scorers\n // but leaves the workflow untouched, so the original execution traces\n // remain accurate and useful for diagnosing score changes.\n const item: EvalItem = {\n input: original.input,\n annotations: original.annotations,\n output: original.output,\n metadata: original.metadata,\n traces: original.traces,\n scores: {},\n scoreDetails: {},\n };\n\n // Same shared scoring path as runEval — determinism, cancellation, and cost\n // accounting all live in scoreItem. Keep the await off the `+=` line so the\n // read-modify-write isn't split by suspension across concurrent items.\n const itemScorerCost = await scoreItem(\n item,\n scorers,\n scorerConcurrency,\n scorerContext,\n options?.signal,\n );\n totalCost += itemScorerCost;\n rescored[itemIndex] = item;\n }\n\n // rescoreItem writes into the pre-allocated `rescored` closure array (the\n // source of truth) and returns void — the pool's returned array is ignored.\n await mapWithConcurrency(result.items, concurrency, (item, i) => rescoreItem(item, i));\n\n const failures = rescored.filter((i) => i.error).length;\n const scorerNames = scorers.map((s) => s.name);\n const scorerStats: EvalSummary['scorers'] = {};\n for (const name of scorerNames) {\n const scores = rescored\n .filter((i) => !i.error && i.scores[name] != null)\n .map((i) => i.scores[name] as number);\n // Same scored/failed surfacing as runEval (table + Studio parity). NOTE:\n // rescore deliberately does NOT support `failOnScorerErrorRate` — it takes\n // RescoreOptions, not EvalConfig, so there's no degradation gate here. The\n // counts are informational; gating belongs to the run that produced output.\n const { scored, failed, skipped } = scorerCounts(rescored, name);\n scorerStats[name] = { ...computeStats(scores), scored, failed, skipped };\n }\n\n const scorerTypes: Record<string, string> = {};\n for (const s of scorers) {\n scorerTypes[s.name] = s.isLlm ? 'llm' : 'deterministic';\n }\n\n return {\n id: randomUUID(),\n dataset: result.dataset,\n metadata: (() => {\n // Strip run group membership — rescored results are independent evaluations.\n // metadata.workflows is preserved via ...rest so the rescored result keeps\n // the same workflow attribution as the original.\n //\n // Also strip the scorer-filtered stamp: whether THIS rescore ran a subset\n // is a property of the rescore invocation, not the source run. A full\n // rescore of a `--scorers`-filtered run would otherwise inherit a stale\n // `scorerFiltered: true` + a `scorersRun` listing scorers it didn't even\n // use — falsely tripping the compare gate and the Studio banner.\n const rest: Record<string, unknown> = { ...result.metadata };\n delete rest.runGroupId;\n delete rest.runIndex;\n delete rest.scorerFiltered;\n delete rest.scorersRun;\n const merged: Record<string, unknown> = {\n ...rest,\n rescored: true,\n originalId: result.id,\n scorerTypes,\n };\n // Backward compatibility: pre-0.14 EvalResult artifacts had `workflow`\n // as a top-level string field with no `metadata.workflows`. Migrate it\n // forward so rescored results from old artifacts retain their workflow\n // attribution under the modern shape.\n if (!Array.isArray(merged.workflows)) {\n const legacyWorkflow = (result as { workflow?: unknown }).workflow;\n if (typeof legacyWorkflow === 'string' && legacyWorkflow) {\n merged.workflows = [legacyWorkflow];\n merged.workflowCounts = { [legacyWorkflow]: result.items.length };\n }\n }\n return merged;\n })(),\n timestamp: new Date().toISOString(),\n totalCost,\n duration: Date.now() - startTime,\n items: rescored,\n summary: { count: result.items.length, failures, scorers: scorerStats },\n };\n}\n","import type { EvalResult } from './types.js';\nimport { randomUUID } from 'node:crypto';\nimport { round } from './utils.js';\n\nexport type MultiRunSummary = {\n runGroupId: string;\n runCount: number;\n /**\n * Workflow names observed across all runs in the group, deduped and ordered\n * by first appearance. Parallel to `EvalResult.metadata.workflows`. A homogeneous\n * multi-run group produced by `axl-eval --runs N` typically has one entry;\n * heterogeneous groups (custom callbacks) can have multiple.\n */\n workflows: string[];\n dataset: string;\n totalCost: number;\n totalDuration: number;\n scorers: Record<\n string,\n {\n mean: number;\n std: number;\n min: number;\n max: number;\n /** Total valid scores summed across all runs in the group. */\n scored?: number;\n /** Total ran-and-failed scorer invocations summed across all runs. */\n failed?: number;\n /** Total `applies`-skipped (N/A) items summed across all runs. Excluded\n * from both the mean and the failure-rate denominator. */\n skipped?: number;\n }\n >;\n timing?: { mean: number; std: number };\n};\n\nfunction std(values: number[], mean: number): number {\n if (values.length <= 1) return 0;\n const sumSqDiffs = values.reduce((sum, v) => sum + (v - mean) ** 2, 0);\n return Math.sqrt(sumSqDiffs / (values.length - 1));\n}\n\n/**\n * Aggregate multiple eval runs into a summary with mean +/- std per scorer.\n */\nexport function aggregateRuns(runs: EvalResult[]): MultiRunSummary {\n if (runs.length === 0) throw new Error('Cannot aggregate zero runs');\n\n const runGroupId = (runs[0].metadata.runGroupId as string) ?? randomUUID();\n const { dataset } = runs[0];\n\n // Union workflow names across all runs in the group, first-seen first.\n // Most groups have one, but custom callbacks can produce heterogeneous ones.\n const seenWorkflows = new Set<string>();\n const workflows: string[] = [];\n for (const run of runs) {\n const list = run.metadata.workflows;\n if (Array.isArray(list)) {\n for (const w of list) {\n if (typeof w === 'string' && !seenWorkflows.has(w)) {\n seenWorkflows.add(w);\n workflows.push(w);\n }\n }\n }\n }\n\n const totalCost = runs.reduce((sum, r) => sum + r.totalCost, 0);\n const totalDuration = runs.reduce((sum, r) => sum + r.duration, 0);\n\n // Collect per-scorer means from each run\n const scorerNames = Object.keys(runs[0].summary.scorers);\n const scorers: MultiRunSummary['scorers'] = {};\n\n for (const name of scorerNames) {\n // A run where this scorer scored ZERO items has an empty-sample mean of 0\n // (computeStats([]) → 0), which would drag the aggregate mean-of-means toward\n // 0 as if it were a real 0.0 score. Exclude such runs from the mean/min/max/std\n // — but only when we can tell: `scored` is absent on pre-0.18.0 artifacts, so\n // those runs are kept (old behavior). If EVERY run scored nothing, fall back to\n // all runs so we never divide by zero.\n const contributing = runs.filter((r) => {\n const sc = r.summary.scorers[name]?.scored;\n return sc == null || sc > 0;\n });\n const meanSource = contributing.length > 0 ? contributing : runs;\n const means = meanSource.map((r) => r.summary.scorers[name]?.mean ?? 0);\n const meanOfMeans = means.reduce((a, b) => a + b, 0) / means.length;\n const minMean = Math.min(...means);\n const maxMean = Math.max(...means);\n\n // Sum the per-run sample sizes across ALL runs (they describe the whole\n // group's thinning, independent of which runs contributed to the mean).\n // Read with `?? 0` — old artifacts predate these fields.\n const scored = runs.reduce((sum, r) => sum + (r.summary.scorers[name]?.scored ?? 0), 0);\n const failed = runs.reduce((sum, r) => sum + (r.summary.scorers[name]?.failed ?? 0), 0);\n const skipped = runs.reduce((sum, r) => sum + (r.summary.scorers[name]?.skipped ?? 0), 0);\n\n scorers[name] = {\n mean: round(meanOfMeans),\n std: round(std(means, meanOfMeans)),\n min: round(minMean),\n max: round(maxMean),\n scored,\n failed,\n skipped,\n };\n }\n\n // Timing aggregation\n let timing: MultiRunSummary['timing'];\n const timingMeans = runs.filter((r) => r.summary.timing).map((r) => r.summary.timing!.mean);\n if (timingMeans.length === runs.length && timingMeans.length > 0) {\n const meanTiming = timingMeans.reduce((a, b) => a + b, 0) / timingMeans.length;\n timing = {\n mean: round(meanTiming),\n std: round(std(timingMeans, meanTiming)),\n };\n }\n\n return {\n runGroupId,\n runCount: runs.length,\n workflows,\n dataset,\n totalCost: round(totalCost),\n totalDuration: round(totalDuration),\n scorers,\n timing,\n };\n}\n"],"mappings":";AAmBO,SAAS,kBACd,aACA,SACmB;AACnB,QAAM,IAAI,YAAY;AACtB,MAAI,MAAM,EAAG,QAAO,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,aAAa,GAAG,cAAc,EAAE;AAEnF,QAAM,aAAa,SAAS,cAAc;AAC1C,QAAM,QAAQ,SAAS,SAAS;AAEhC,QAAM,OAAO,YAAY,OAAO,CAAC,GAAG,MAAM,IAAI,GAAG,CAAC,IAAI;AAEtD,MAAI,MAAM;AACR,WAAO;AAAA,MACL,OAAO,YAAY,CAAC;AAAA,MACpB,OAAO,YAAY,CAAC;AAAA,MACpB;AAAA,MACA,aAAa,OAAO,IAAI,IAAI;AAAA,MAC5B,cAAc,OAAO,IAAI,IAAI;AAAA,IAC/B;AAEF,MAAI,cAAc;AAChB,WAAO;AAAA,MACL,OAAO,MAAM,IAAI;AAAA,MACjB,OAAO,MAAM,IAAI;AAAA,MACjB,MAAM,MAAM,IAAI;A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