@axlsdk/eval 0.16.1 → 0.17.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 +18 -2
- package/dist/{chunk-CV6VE5VT.js → chunk-NPKIP4SB.js} +37 -9
- package/dist/chunk-NPKIP4SB.js.map +1 -0
- package/dist/cli.cjs +161 -93
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +124 -74
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +36 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-CV6VE5VT.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
evalCompare,
|
|
5
5
|
rescore,
|
|
6
6
|
runEval
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-NPKIP4SB.js";
|
|
8
8
|
|
|
9
9
|
// src/cli.ts
|
|
10
10
|
import { readdirSync, statSync } from "fs";
|
|
@@ -12,65 +12,52 @@ import { readFile as readFileAsync, writeFile as writeFileAsync, mkdir } from "f
|
|
|
12
12
|
import * as path from "path";
|
|
13
13
|
|
|
14
14
|
// src/cli-utils.ts
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
import {
|
|
16
|
+
resolveRuntime,
|
|
17
|
+
pickDefault,
|
|
18
|
+
pickExport,
|
|
19
|
+
CONFIG_CANDIDATES,
|
|
20
|
+
findConfig,
|
|
21
|
+
needsTsxLoader,
|
|
22
|
+
importModule,
|
|
23
|
+
expandGlob,
|
|
24
|
+
registerConditions
|
|
25
|
+
} from "@axlsdk/axl";
|
|
26
|
+
|
|
27
|
+
// src/cli-validate.ts
|
|
28
|
+
function validateEvalConfig(cfg) {
|
|
29
|
+
if (!cfg || typeof cfg !== "object") {
|
|
30
|
+
return `does not export a valid eval config \u2014 got ${cfg === null ? "null" : typeof cfg}.`;
|
|
28
31
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
var tsImportFn;
|
|
39
|
-
async function importModule(filePath, parentURL) {
|
|
40
|
-
if (needsTsxLoader(filePath)) {
|
|
41
|
-
if (tsImportFn === void 0) {
|
|
42
|
-
try {
|
|
43
|
-
const mod = await import("tsx/esm/api");
|
|
44
|
-
tsImportFn = mod.tsImport ?? null;
|
|
45
|
-
} catch {
|
|
46
|
-
tsImportFn = null;
|
|
47
|
-
console.warn(
|
|
48
|
-
"[axl-eval] Warning: tsx is not installed. TypeScript files require tsx.\n Install it with: npm install -D tsx"
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (tsImportFn) {
|
|
53
|
-
return await tsImportFn(pathToFileURL(filePath).href, parentURL);
|
|
54
|
-
}
|
|
32
|
+
const c = cfg;
|
|
33
|
+
const missing = [];
|
|
34
|
+
if (!c.workflow) missing.push("workflow");
|
|
35
|
+
if (!c.dataset) missing.push("dataset");
|
|
36
|
+
if (!c.scorers) missing.push("scorers");
|
|
37
|
+
if (missing.length > 0) {
|
|
38
|
+
const keys = Object.keys(c).slice(0, 10);
|
|
39
|
+
const got = keys.length > 0 ? ` Got: { ${keys.join(", ")} }.` : "";
|
|
40
|
+
return `does not export a valid eval config (missing ${missing.join(", ")}).${got}`;
|
|
55
41
|
}
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const hookCode = [
|
|
62
|
-
`const extra = ${JSON.stringify(conditions)};`,
|
|
63
|
-
`export async function resolve(specifier, context, nextResolve) {`,
|
|
64
|
-
` return nextResolve(specifier, {`,
|
|
65
|
-
` ...context,`,
|
|
66
|
-
` conditions: [...new Set([...context.conditions, ...extra])],`,
|
|
67
|
-
` });`,
|
|
68
|
-
`}`
|
|
69
|
-
].join("\n");
|
|
70
|
-
nodeModule.register(`data:text/javascript,${encodeURIComponent(hookCode)}`);
|
|
71
|
-
} catch {
|
|
72
|
-
console.warn("[axl-eval] Warning: --conditions requires Node.js 20.6+");
|
|
42
|
+
if (typeof c.workflow !== "string") {
|
|
43
|
+
return `exports a non-string workflow (got ${typeof c.workflow}) \u2014 workflow must be the registered workflow name.`;
|
|
44
|
+
}
|
|
45
|
+
if (typeof c.dataset !== "object" || Array.isArray(c.dataset)) {
|
|
46
|
+
return `exports a non-object dataset (got ${Array.isArray(c.dataset) ? "array" : typeof c.dataset}) \u2014 use the dataset() factory.`;
|
|
73
47
|
}
|
|
48
|
+
if (typeof c.dataset.getItems !== "function") {
|
|
49
|
+
return `exports a dataset without a getItems() method \u2014 use the dataset() factory.`;
|
|
50
|
+
}
|
|
51
|
+
if (!Array.isArray(c.scorers) || c.scorers.length === 0) {
|
|
52
|
+
return `exports an empty scorers array \u2014 at least one scorer is required.`;
|
|
53
|
+
}
|
|
54
|
+
const badScorerIdx = c.scorers.findIndex(
|
|
55
|
+
(s) => !s || typeof s.score !== "function"
|
|
56
|
+
);
|
|
57
|
+
if (badScorerIdx !== -1) {
|
|
58
|
+
return `exports a scorers array with a non-scorer entry at index ${badScorerIdx} \u2014 each scorer must have a score() method (use the scorer() factory).`;
|
|
59
|
+
}
|
|
60
|
+
return void 0;
|
|
74
61
|
}
|
|
75
62
|
|
|
76
63
|
// src/cli.ts
|
|
@@ -226,9 +213,15 @@ async function runRescore(args) {
|
|
|
226
213
|
const runtime = await getRuntime(configArg, conditions);
|
|
227
214
|
try {
|
|
228
215
|
const mod = await importModule(path.resolve(evalFilePath), import.meta.url);
|
|
229
|
-
const evalConfig = mod
|
|
230
|
-
if (!evalConfig
|
|
231
|
-
console.error(
|
|
216
|
+
const evalConfig = pickDefault(mod);
|
|
217
|
+
if (!evalConfig || typeof evalConfig !== "object") {
|
|
218
|
+
console.error(
|
|
219
|
+
`Error: ${evalFilePath} does not export an eval config object \u2014 got ${evalConfig === null ? "null" : typeof evalConfig}.`
|
|
220
|
+
);
|
|
221
|
+
process.exit(1);
|
|
222
|
+
}
|
|
223
|
+
if (!Array.isArray(evalConfig.scorers) || evalConfig.scorers.length === 0) {
|
|
224
|
+
console.error(`Error: ${evalFilePath} does not export a non-empty scorers array.`);
|
|
232
225
|
process.exit(1);
|
|
233
226
|
}
|
|
234
227
|
const rescored = [];
|
|
@@ -251,6 +244,7 @@ async function runRescore(args) {
|
|
|
251
244
|
}
|
|
252
245
|
}
|
|
253
246
|
function collectEvalFiles(p) {
|
|
247
|
+
if (p.includes("*")) return expandGlob(p, process.cwd());
|
|
254
248
|
const resolved = path.resolve(p);
|
|
255
249
|
try {
|
|
256
250
|
const stat = statSync(resolved);
|
|
@@ -461,26 +455,38 @@ async function runEvalCommand(args) {
|
|
|
461
455
|
}
|
|
462
456
|
const runtime = await getRuntime(configArg, conditions);
|
|
463
457
|
const results = [];
|
|
458
|
+
let failedFiles = 0;
|
|
464
459
|
try {
|
|
465
460
|
for (const filePath of evalFiles) {
|
|
466
461
|
try {
|
|
467
462
|
const mod = await importModule(path.resolve(filePath), import.meta.url);
|
|
468
|
-
const evalConfig = mod
|
|
469
|
-
|
|
463
|
+
const evalConfig = pickDefault(mod);
|
|
464
|
+
const validationError = validateEvalConfig(evalConfig);
|
|
465
|
+
if (validationError) {
|
|
466
|
+
console.error(`Error: ${filePath} ${validationError}`);
|
|
467
|
+
failedFiles++;
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
const exported = pickExport(mod, "executeWorkflow");
|
|
471
|
+
let customExecute;
|
|
472
|
+
if (typeof exported === "function") {
|
|
473
|
+
customExecute = exported;
|
|
474
|
+
} else if (exported !== void 0) {
|
|
470
475
|
console.error(
|
|
471
|
-
`Error: ${filePath}
|
|
476
|
+
`[axl-eval] Error: ${filePath} exports executeWorkflow but it is ${typeof exported}, not a function.`
|
|
472
477
|
);
|
|
478
|
+
failedFiles++;
|
|
473
479
|
continue;
|
|
474
480
|
}
|
|
475
481
|
let executeWorkflow;
|
|
476
|
-
if (
|
|
482
|
+
if (customExecute) {
|
|
477
483
|
executeWorkflow = async (input, rt) => {
|
|
478
484
|
const {
|
|
479
485
|
result,
|
|
480
486
|
cost: trackedCost,
|
|
481
487
|
metadata
|
|
482
488
|
} = await runtime.trackExecution(async () => {
|
|
483
|
-
return
|
|
489
|
+
return customExecute(input, rt);
|
|
484
490
|
});
|
|
485
491
|
return {
|
|
486
492
|
output: result.output,
|
|
@@ -496,26 +502,69 @@ async function runEvalCommand(args) {
|
|
|
496
502
|
return { output: result, cost, metadata };
|
|
497
503
|
};
|
|
498
504
|
} else {
|
|
499
|
-
|
|
500
|
-
|
|
505
|
+
const exportShape = (() => {
|
|
506
|
+
const top = Object.keys(mod).filter((k) => k !== "default");
|
|
507
|
+
const fromDefault = mod.default && typeof mod.default === "object" ? Object.keys(mod.default) : [];
|
|
508
|
+
const all = [.../* @__PURE__ */ new Set([...top, ...fromDefault])];
|
|
509
|
+
return all.length > 0 ? `Found exports: [${all.join(", ")}].` : "";
|
|
510
|
+
})();
|
|
511
|
+
console.error(
|
|
512
|
+
`[axl-eval] Error: ${filePath} does not export an executeWorkflow function and no workflow named "${evalConfig.workflow}" is registered on the runtime.
|
|
513
|
+
` + (exportShape ? ` ${exportShape}
|
|
514
|
+
` : "") + ` Add either:
|
|
515
|
+
export async function executeWorkflow(input, runtime) { ... }
|
|
516
|
+
or register the workflow on your runtime via runtime.registerWorkflow(workflow).
|
|
517
|
+
Tip: if your eval previously worked, your package.json may be missing
|
|
518
|
+
"type": "module" \u2014 tsx loads .ts as CJS, putting named exports on
|
|
519
|
+
mod.default.<name>. The CLI handles that interop, but if you renamed
|
|
520
|
+
or removed the export the file path is your fix.`
|
|
501
521
|
);
|
|
502
|
-
|
|
522
|
+
failedFiles++;
|
|
523
|
+
continue;
|
|
503
524
|
}
|
|
504
525
|
const runOptions = captureTraces ? { captureTraces: true } : void 0;
|
|
505
526
|
if (runs > 1) {
|
|
506
527
|
const { randomUUID } = await import("crypto");
|
|
507
528
|
const runGroupId = randomUUID();
|
|
508
529
|
const runResults = [];
|
|
530
|
+
let runFailure;
|
|
509
531
|
for (let r = 0; r < runs; r++) {
|
|
510
532
|
console.error(`[axl-eval] Run ${r + 1}/${runs}...`);
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
533
|
+
try {
|
|
534
|
+
const result = await runEval(evalConfig, executeWorkflow, runtime, runOptions);
|
|
535
|
+
result.metadata.runGroupId = runGroupId;
|
|
536
|
+
result.metadata.runIndex = r;
|
|
537
|
+
runResults.push(result);
|
|
538
|
+
} catch (err) {
|
|
539
|
+
runFailure = err instanceof Error ? err : new Error(String(err));
|
|
540
|
+
console.error(`[axl-eval] Run ${r + 1}/${runs} failed: ${runFailure.message}`);
|
|
541
|
+
break;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
if (runResults.length === 0) {
|
|
545
|
+
console.error(
|
|
546
|
+
`[axl-eval] Aborting ${filePath}: no runs completed (${runFailure?.message ?? "unknown failure"}).`
|
|
547
|
+
);
|
|
548
|
+
failedFiles++;
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
const partial = runResults.length < runs;
|
|
552
|
+
if (partial) {
|
|
553
|
+
const failureMsg = runFailure ? runFailure.message || String(runFailure) || void 0 : void 0;
|
|
554
|
+
for (const r of runResults) {
|
|
555
|
+
r.metadata.fromPartialBatch = true;
|
|
556
|
+
r.metadata.batchCompleted = runResults.length;
|
|
557
|
+
r.metadata.batchAttempted = runs;
|
|
558
|
+
if (failureMsg) r.metadata.batchFailure = failureMsg;
|
|
559
|
+
}
|
|
560
|
+
console.error(
|
|
561
|
+
`[axl-eval] PARTIAL: ${runResults.length} of ${runs} runs completed for ${filePath}.`
|
|
562
|
+
);
|
|
563
|
+
failedFiles++;
|
|
516
564
|
}
|
|
517
565
|
const summary = aggregateRuns(runResults);
|
|
518
566
|
console.log("\n" + formatMultiRunTable(summary) + "\n");
|
|
567
|
+
for (const r of runResults) results.push(r);
|
|
519
568
|
} else {
|
|
520
569
|
const result = await runEval(evalConfig, executeWorkflow, runtime, runOptions);
|
|
521
570
|
results.push(result);
|
|
@@ -525,6 +574,7 @@ async function runEvalCommand(args) {
|
|
|
525
574
|
console.error(
|
|
526
575
|
`Error running eval ${filePath}: ${err instanceof Error ? err.message : String(err)}`
|
|
527
576
|
);
|
|
577
|
+
failedFiles++;
|
|
528
578
|
}
|
|
529
579
|
}
|
|
530
580
|
if (outputPath && results.length > 0) {
|
|
@@ -538,7 +588,7 @@ async function runEvalCommand(args) {
|
|
|
538
588
|
await runtime.shutdown().catch(() => {
|
|
539
589
|
});
|
|
540
590
|
}
|
|
541
|
-
if (results.length === 0) {
|
|
591
|
+
if (failedFiles > 0 || results.length === 0) {
|
|
542
592
|
process.exit(1);
|
|
543
593
|
}
|
|
544
594
|
}
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts","../src/cli-utils.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { readdirSync, statSync } from 'node:fs';\nimport { readFile as readFileAsync, writeFile as writeFileAsync, mkdir } from 'node:fs/promises';\nimport * as path from 'node:path';\nimport type { AxlRuntime } from '@axlsdk/axl';\nimport { evalCompare } from './compare.js';\nimport { runEval } from './runner.js';\nimport { rescore } from './rescore.js';\nimport { aggregateRuns } from './multi-run.js';\nimport type { MultiRunSummary } from './multi-run.js';\nimport type { EvalConfig, EvalResult } from './types.js';\nimport {\n findConfig,\n resolveRuntime,\n importModule,\n registerConditions,\n CONFIG_CANDIDATES,\n} from './cli-utils.js';\n\nconst KNOWN_FLAGS = new Set([\n '--output',\n '--config',\n '--conditions',\n '--fail-on-regression',\n '--threshold',\n '--runs',\n '--capture-traces',\n]);\n\nasync function main() {\n const args = process.argv.slice(2);\n\n if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {\n console.log(`\nUsage:\n axl-eval <path> Run eval file(s)\n axl-eval <path> --runs <n> Run eval N times (multi-run)\n axl-eval <path> --output <file> Save results to JSON\n axl-eval <path> --config <file> Use config file for runtime\n axl-eval <path> --conditions <list> Node.js import conditions (comma-separated)\n axl-eval <path> --capture-traces Populate EvalItem.traces on every item\n (success + failure). Adds memory\n overhead proportional to dataset size\n x turns x agents; off by default.\n axl-eval rescore <results> <eval-file> Re-run scorers on saved outputs\n axl-eval compare <a> <b> Compare two eval result files\n axl-eval compare <a> <b> --threshold <v> Set regression threshold (global or per-scorer)\n axl-eval compare <a> <b> --fail-on-regression Exit 1 if regressions\n\nConfig auto-detection (when --config is not specified):\n ${CONFIG_CANDIDATES.join(' -> ')}\n\nWhen a config is found, the exported AxlRuntime is passed to executeWorkflow\nand cost is tracked automatically via runtime.trackCost().\nWhen no config is found, a bare AxlRuntime is created (providers from env vars).\n`);\n process.exit(0);\n }\n\n if (args[0] === 'compare') {\n await runCompare(args.slice(1));\n return;\n }\n\n if (args[0] === 'rescore') {\n await runRescore(args.slice(1));\n return;\n }\n\n await runEvalCommand(args);\n}\n\nfunction parseThresholdArg(args: string[]): Record<string, number> | number | undefined {\n const idx = args.indexOf('--threshold');\n if (idx === -1 || idx + 1 >= args.length) return undefined;\n const value = args[idx + 1];\n\n // Global numeric threshold: --threshold 0.05\n if (/^[\\d.]+$/.test(value)) return parseFloat(value);\n\n // Per-scorer map: --threshold accuracy=0,tone=0.1\n const map: Record<string, number> = {};\n for (const pair of value.split(',')) {\n const [key, val] = pair.split('=');\n if (key && val != null) map[key.trim()] = parseFloat(val.trim());\n }\n return Object.keys(map).length > 0 ? map : undefined;\n}\n\nasync function runCompare(args: string[]) {\n const failOnRegression = args.includes('--fail-on-regression');\n const thresholds = parseThresholdArg(args);\n const files = args.filter(\n (a, i) => !a.startsWith('--') && !(i > 0 && args[i - 1] === '--threshold'),\n );\n\n if (files.length !== 2) {\n console.error('Usage: axl-eval compare <baseline.json> <candidate.json> [--threshold <value>]');\n process.exit(1);\n }\n\n const baselineRaw = JSON.parse(await readFileAsync(files[0], 'utf-8'));\n const candidateRaw = JSON.parse(await readFileAsync(files[1], 'utf-8'));\n const baseline: EvalResult | EvalResult[] = baselineRaw;\n const candidate: EvalResult | EvalResult[] = candidateRaw;\n const compareOptions = thresholds != null ? { thresholds } : undefined;\n const comparison = evalCompare(baseline, candidate, compareOptions);\n\n console.log(\n `\\nCompare: baseline (${comparison.baseline.id.slice(0, 8)}) -> candidate (${comparison.candidate.id.slice(0, 8)})\\n`,\n );\n\n const scorerNames = Object.keys(comparison.scorers);\n const maxNameLen = Math.max(...scorerNames.map((n) => n.length), 6);\n const hasCI = scorerNames.some((n) => comparison.scorers[n].ci != null);\n\n const ciHeader = hasCI ? ' CI 95% Sig' : '';\n const ciRule = hasCI ? ' ---------------- ---' : '';\n console.log(` ${'Scorer'.padEnd(maxNameLen)} Baseline Candidate Delta Change${ciHeader}`);\n console.log(` ${''.padEnd(maxNameLen, '-')} -------- --------- -------- ------${ciRule}`);\n\n for (const name of scorerNames) {\n const s = comparison.scorers[name];\n const sign = s.delta > 0 ? '+' : '';\n let line = ` ${name.padEnd(maxNameLen)} ${s.baselineMean.toFixed(3).padStart(8)} ${s.candidateMean.toFixed(3).padStart(9)} ${(sign + s.delta.toFixed(3)).padStart(8)} ${(sign + s.deltaPercent.toFixed(1) + '%').padStart(6)}`;\n if (hasCI) {\n if (s.ci) {\n const lo = (s.ci.lower >= 0 ? '+' : '') + s.ci.lower.toFixed(4);\n const hi = (s.ci.upper >= 0 ? '+' : '') + s.ci.upper.toFixed(4);\n const sig = s.significant ? ' *' : ' ';\n line += ` [${lo}, ${hi}]${sig}`;\n } else {\n line += ' —'.padEnd(22);\n }\n }\n console.log(line);\n }\n\n if (comparison.timing) {\n const t = comparison.timing;\n const sign = t.delta > 0 ? '+' : '';\n console.log(\n `\\n Timing: baseline ${(t.baselineMean / 1000).toFixed(2)}s -> candidate ${(t.candidateMean / 1000).toFixed(2)}s (${sign}${t.deltaPercent.toFixed(1)}%)`,\n );\n }\n if (comparison.cost) {\n const c = comparison.cost;\n const sign = c.delta > 0 ? '+' : '';\n console.log(\n ` Cost: baseline $${c.baselineTotal.toFixed(2)} -> candidate $${c.candidateTotal.toFixed(2)} (${sign}${c.deltaPercent.toFixed(1)}%)`,\n );\n }\n\n const baselineRef = Array.isArray(baseline) ? baseline[0] : baseline;\n const stable = Math.max(\n 0,\n baselineRef.items.length - comparison.regressions.length - comparison.improvements.length,\n );\n console.log(\n `\\n Regressions: ${comparison.regressions.length} | Improvements: ${comparison.improvements.length} | Stable: ${stable}\\n`,\n );\n\n if (failOnRegression && comparison.regressions.length > 0) {\n // When CI is available, only fail on significant regressions\n const hasSignificance = scorerNames.some((n) => comparison.scorers[n].significant != null);\n if (hasSignificance) {\n const hasSignificantRegression = scorerNames.some(\n (n) => comparison.scorers[n].significant === true && comparison.scorers[n].delta < 0,\n );\n if (hasSignificantRegression) process.exit(1);\n } else {\n process.exit(1);\n }\n }\n}\n\nasync function runRescore(args: string[]) {\n const { outputPath, configArg, conditions, paths } = parseEvalArgs(args);\n\n if (paths.length < 2) {\n console.error('Usage: axl-eval rescore <results.json> <eval-file> [--output <file>]');\n process.exit(1);\n }\n\n const [resultsPath, evalFilePath] = paths;\n const raw = JSON.parse(await readFileAsync(resultsPath, 'utf-8'));\n const results: EvalResult[] = Array.isArray(raw) ? raw : [raw];\n\n const runtime = await getRuntime(configArg, conditions);\n try {\n const mod = await importModule(path.resolve(evalFilePath), import.meta.url);\n const evalConfig: EvalConfig = mod.default?.default ?? mod.default ?? mod.config ?? mod;\n\n if (!evalConfig.scorers || evalConfig.scorers.length === 0) {\n console.error(`Error: ${evalFilePath} does not export scorers`);\n process.exit(1);\n }\n\n const rescored: EvalResult[] = [];\n for (const resultData of results) {\n rescored.push(await rescore(resultData, evalConfig.scorers, runtime));\n }\n\n for (const r of rescored) {\n console.log('\\n' + formatTable(r) + '\\n');\n }\n\n if (outputPath) {\n const output = Array.isArray(raw) ? rescored : rescored[0];\n const outputDir = path.dirname(path.resolve(outputPath));\n await mkdir(outputDir, { recursive: true });\n await writeFileAsync(outputPath, JSON.stringify(output, null, 2), 'utf-8');\n console.log(`Rescored results saved to ${outputPath}`);\n }\n } finally {\n await runtime.shutdown().catch(() => {});\n }\n}\n\nfunction collectEvalFiles(p: string): string[] {\n const resolved = path.resolve(p);\n try {\n const stat = statSync(resolved);\n if (stat.isDirectory()) {\n const entries = readdirSync(resolved);\n return entries\n .filter((e) => /\\.eval\\.[mc]?[jt]sx?$/.test(e))\n .map((e) => path.join(resolved, e));\n }\n return [resolved];\n } catch {\n return [resolved];\n }\n}\n\n/** Render observed workflows for a terse header line. Multiple → comma-separated. */\nfunction formatWorkflows(workflows: unknown): string {\n if (!Array.isArray(workflows) || workflows.length === 0) return '(unknown)';\n return (workflows as unknown[]).filter((w): w is string => typeof w === 'string').join(', ');\n}\n\nfunction formatTable(result: EvalResult): string {\n const lines: string[] = [];\n const scorerNames = Object.keys(result.summary.scorers);\n const maxNameLen = Math.max(...scorerNames.map((n) => n.length), 'Scorer'.length);\n const colWidth = 8;\n\n lines.push(\n `Eval: ${formatWorkflows(result.metadata.workflows)} x ${result.dataset} (${result.summary.count} items)`,\n );\n lines.push(\n ` ${'Scorer'.padEnd(maxNameLen)} ${'Mean'.padStart(colWidth)} ${'Min'.padStart(colWidth)} ${'Max'.padStart(colWidth)} ${'p50'.padStart(colWidth)} ${'p95'.padStart(colWidth)}`,\n );\n\n const ruleLen = maxNameLen + 2 + (colWidth + 2) * 5;\n lines.push(' ' + '\\u2500'.repeat(ruleLen));\n\n for (const name of scorerNames) {\n const s = result.summary.scorers[name];\n // Detect scorers with no valid scores (all items errored → computeStats([]) → all zeros)\n const validScoreCount = result.items.filter((i) => !i.error && i.scores[name] != null).length;\n if (validScoreCount === 0) {\n lines.push(\n ` ${name.padEnd(maxNameLen)} ${'--'.padStart(colWidth)} ${'--'.padStart(colWidth)} ${'--'.padStart(colWidth)} ${'--'.padStart(colWidth)} ${'--'.padStart(colWidth)}`,\n );\n } else {\n lines.push(\n ` ${name.padEnd(maxNameLen)} ${s.mean.toFixed(2).padStart(colWidth)} ${s.min.toFixed(2).padStart(colWidth)} ${s.max.toFixed(2).padStart(colWidth)} ${s.p50.toFixed(2).padStart(colWidth)} ${s.p95.toFixed(2).padStart(colWidth)}`,\n );\n }\n }\n\n if (result.summary.timing) {\n const t = result.summary.timing;\n lines.push(\n ` ${'Timing'.padEnd(maxNameLen)} ${(t.mean / 1000).toFixed(2).padStart(colWidth)}s ${(t.p50 / 1000).toFixed(2).padStart(colWidth)}s ${(t.p95 / 1000).toFixed(2).padStart(colWidth)}s`,\n );\n }\n\n const durationSec = (result.duration / 1000).toFixed(1);\n const costStr = result.totalCost > 0 ? `$${result.totalCost.toFixed(2)}` : '$0.00';\n lines.push('');\n lines.push(\n ` Failures: ${result.summary.failures}/${result.summary.count} | Cost: ${costStr} | Duration: ${durationSec}s`,\n );\n\n const itemsWithErrors = result.items.filter((i) => i.scorerErrors?.length);\n if (itemsWithErrors.length > 0) {\n const uniqueErrors = [...new Set(itemsWithErrors.flatMap((i) => i.scorerErrors!))];\n lines.push('');\n lines.push(\n ` Scorer errors (${itemsWithErrors.length}/${result.summary.count} items affected):`,\n );\n for (const err of uniqueErrors.slice(0, 5)) {\n lines.push(` - ${err}`);\n }\n if (uniqueErrors.length > 5) {\n lines.push(` ... and ${uniqueErrors.length - 5} more`);\n }\n }\n\n return lines.join('\\n');\n}\n\nfunction formatMultiRunTable(summary: MultiRunSummary): string {\n const lines: string[] = [];\n const scorerNames = Object.keys(summary.scorers);\n const maxNameLen = Math.max(...scorerNames.map((n) => n.length), 'Scorer'.length);\n const colWidth = 16;\n\n lines.push(\n `Eval: ${formatWorkflows(summary.workflows)} x ${summary.dataset} \\u2014 ${summary.runCount} runs`,\n );\n lines.push(\n ` ${'Scorer'.padEnd(maxNameLen)} ${'Mean \\u00b1 Std'.padStart(colWidth)} ${'Min'.padStart(8)} ${'Max'.padStart(8)}`,\n );\n const ruleLen = maxNameLen + 2 + colWidth + 2 + 8 + 2 + 8;\n lines.push(' ' + '\\u2500'.repeat(ruleLen));\n\n for (const name of scorerNames) {\n const s = summary.scorers[name];\n const meanStd = `${s.mean.toFixed(3)} \\u00b1 ${s.std.toFixed(3)}`;\n lines.push(\n ` ${name.padEnd(maxNameLen)} ${meanStd.padStart(colWidth)} ${s.min.toFixed(3).padStart(8)} ${s.max.toFixed(3).padStart(8)}`,\n );\n }\n\n if (summary.timing) {\n lines.push(\n ` ${'Timing'.padEnd(maxNameLen)} ${((summary.timing.mean / 1000).toFixed(2) + ' \\u00b1 ' + (summary.timing.std / 1000).toFixed(2) + 's').padStart(colWidth)}`,\n );\n }\n\n const costStr = summary.totalCost > 0 ? `$${summary.totalCost.toFixed(2)}` : '$0.00';\n const durationStr = (summary.totalDuration / 1000).toFixed(1);\n lines.push('');\n lines.push(` Total Cost: ${costStr} | Total Duration: ${durationStr}s`);\n\n return lines.join('\\n');\n}\n\n// ── Runtime resolution ─────────────────────────────────────────────\n\nasync function resolveRuntimeFromConfig(configPath: string): Promise<AxlRuntime> {\n try {\n const mod = await importModule(configPath, import.meta.url);\n const runtime = resolveRuntime(mod) as AxlRuntime;\n\n if (!runtime || typeof runtime.execute !== 'function') {\n console.error(`Config must export a default AxlRuntime instance.`);\n if (runtime) {\n const keys = Object.keys(runtime as object)\n .slice(0, 5)\n .join(', ');\n console.error(` Got: ${typeof runtime}${keys ? ` with keys: { ${keys} }` : ''}`);\n }\n console.error(\n `Example:\\n import { AxlRuntime } from '@axlsdk/axl';\\n export default new AxlRuntime({ ... });`,\n );\n process.exit(1);\n }\n\n return runtime;\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n if (\n /Cannot use import statement|Unexpected reserved word|top-level await|exports is not defined/.test(\n msg,\n )\n ) {\n const ext = path.extname(configPath);\n console.error(`[axl-eval] Config failed to load due to a CJS/ESM compatibility issue.`);\n if (ext === '.ts' || ext === '.tsx') {\n console.error(\n ` Tip: try renaming to .mts to force ESM format, or ensure tsx is installed and up to date.`,\n );\n } else {\n console.error(` Tip: add \"type\": \"module\" to your package.json.`);\n }\n console.error();\n }\n console.error(`Failed to load config:`, err);\n process.exit(1);\n }\n}\n\nasync function getRuntime(configArg?: string, conditions?: string[]): Promise<AxlRuntime> {\n // Register import conditions before any config loading\n if (conditions && conditions.length > 0) {\n await registerConditions(conditions);\n }\n\n // 1. Explicit --config\n if (configArg) {\n const configPath = path.resolve(process.cwd(), configArg);\n const stat = statSync(configPath, { throwIfNoEntry: false });\n if (!stat?.isFile()) {\n console.error(`Config file not found: ${configPath}`);\n process.exit(1);\n }\n console.error(`[axl-eval] Loading config from ${configPath}`);\n return resolveRuntimeFromConfig(configPath);\n }\n\n // 2. Auto-detect\n const found = findConfig(process.cwd());\n if (found) {\n console.error(`[axl-eval] Auto-detected config: ${found}`);\n return resolveRuntimeFromConfig(found);\n }\n\n // 3. Bare runtime (providers from env vars)\n const { AxlRuntime } = await import('@axlsdk/axl');\n return new AxlRuntime();\n}\n\n// ── Arg parsing ────────────────────────────────────────────────────\n\nfunction parseEvalArgs(args: string[]): {\n outputPath?: string;\n configArg?: string;\n conditions: string[];\n runs: number;\n captureTraces: boolean;\n paths: string[];\n} {\n let outputPath: string | undefined;\n let configArg: string | undefined;\n let conditions: string[] = [];\n let runs = 1;\n let captureTraces = false;\n const paths: string[] = [];\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (arg === '--output' || arg === '--config' || arg === '--conditions' || arg === '--runs') {\n if (i + 1 >= args.length) {\n console.error(`Error: ${arg} requires a value`);\n process.exit(1);\n }\n const value = args[++i];\n if (arg === '--output') outputPath = value;\n else if (arg === '--config') configArg = value;\n else if (arg === '--runs') runs = Math.max(1, parseInt(value, 10) || 1);\n else\n conditions = value\n .split(',')\n .map((c) => c.trim())\n .filter(Boolean);\n } else if (arg === '--capture-traces') {\n // Boolean flag — no value consumed.\n captureTraces = true;\n } else if (arg.startsWith('--')) {\n if (!KNOWN_FLAGS.has(arg)) {\n console.error(`Unknown flag: ${arg}`);\n process.exit(1);\n }\n } else {\n paths.push(arg);\n }\n }\n\n return { outputPath, configArg, conditions, runs, captureTraces, paths };\n}\n\n// ── Main eval command ──────────────────────────────────────────────\n\nasync function runEvalCommand(args: string[]) {\n const { outputPath, configArg, conditions, runs, captureTraces, paths } = parseEvalArgs(args);\n\n if (paths.length === 0) {\n console.error('Error: No eval file path provided');\n process.exit(1);\n }\n\n const evalFiles: string[] = [];\n for (const p of paths) {\n evalFiles.push(...collectEvalFiles(p));\n }\n\n if (evalFiles.length === 0) {\n console.error('Error: No eval files found');\n process.exit(1);\n }\n\n const runtime = await getRuntime(configArg, conditions);\n const results: EvalResult[] = [];\n\n try {\n for (const filePath of evalFiles) {\n try {\n const mod = await importModule(path.resolve(filePath), import.meta.url);\n const evalConfig: EvalConfig = mod.default?.default ?? mod.default ?? mod.config ?? mod;\n\n if (!evalConfig.workflow || !evalConfig.dataset || !evalConfig.scorers) {\n console.error(\n `Error: ${filePath} does not export a valid eval config (missing workflow, dataset, or scorers)`,\n );\n continue;\n }\n\n // Resolve executeWorkflow: custom export > registered workflow > passthrough\n let executeWorkflow: (\n input: unknown,\n rt?: unknown,\n ) => Promise<{ output: unknown; cost?: number; metadata?: Record<string, unknown> }>;\n\n if (mod.executeWorkflow) {\n // Wrap custom executeWorkflow with trackExecution for cost + metadata attribution\n executeWorkflow = async (input, rt) => {\n const {\n result,\n cost: trackedCost,\n metadata,\n } = await runtime.trackExecution(async () => {\n return mod.executeWorkflow(input, rt);\n });\n return {\n output: result.output,\n cost: result.cost ?? trackedCost,\n metadata: result.metadata ?? metadata,\n };\n };\n } else if (runtime.getWorkflow(evalConfig.workflow)) {\n // No executeWorkflow exported but workflow is registered — use runtime.execute()\n executeWorkflow = async (input) => {\n const { result, cost, metadata } = await runtime.trackExecution(async () => {\n return runtime.execute(evalConfig.workflow, input);\n });\n return { output: result, cost, metadata };\n };\n } else {\n console.warn(\n `[axl-eval] Warning: ${filePath} does not export executeWorkflow — using input passthrough`,\n );\n executeWorkflow = async (input) => ({ output: input });\n }\n\n // When --capture-traces is set, forward it to runEval so the runner\n // wraps each item's execution in a nested trackExecution({ captureTraces: true }).\n // This populates EvalItem.traces on both success (via tracked.traces)\n // and failure (via the axlCapturedTraces side-channel on the thrown\n // error). Nested trackExecution scopes walk the AsyncLocalStorage\n // parent chain, so the outer trackExecution above still observes\n // cost/metadata correctly.\n const runOptions = captureTraces ? { captureTraces: true } : undefined;\n\n if (runs > 1) {\n // Multi-run mode\n const { randomUUID } = await import('node:crypto');\n const runGroupId = randomUUID();\n const runResults: EvalResult[] = [];\n\n for (let r = 0; r < runs; r++) {\n console.error(`[axl-eval] Run ${r + 1}/${runs}...`);\n const result = await runEval(evalConfig, executeWorkflow, runtime, runOptions);\n result.metadata.runGroupId = runGroupId;\n result.metadata.runIndex = r;\n runResults.push(result);\n results.push(result);\n }\n\n const summary = aggregateRuns(runResults);\n console.log('\\n' + formatMultiRunTable(summary) + '\\n');\n } else {\n const result = await runEval(evalConfig, executeWorkflow, runtime, runOptions);\n results.push(result);\n\n console.log('\\n' + formatTable(result) + '\\n');\n }\n } catch (err) {\n console.error(\n `Error running eval ${filePath}: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n }\n\n if (outputPath && results.length > 0) {\n const output = results.length === 1 ? results[0] : results;\n const outputDir = path.dirname(path.resolve(outputPath));\n await mkdir(outputDir, { recursive: true });\n await writeFileAsync(outputPath, JSON.stringify(output, null, 2), 'utf-8');\n console.log(`Results saved to ${outputPath}`);\n }\n } finally {\n await runtime.shutdown().catch(() => {});\n }\n\n // Exit with non-zero code if no evals succeeded\n if (results.length === 0) {\n process.exit(1);\n }\n}\n\nmain().catch((err) => {\n console.error(err);\n process.exit(1);\n});\n","/**\n * CLI utilities for config detection, runtime resolution, and loader registration.\n *\n * These are duplicated from @axlsdk/studio (cli-utils.ts, resolve-runtime.ts,\n * eval-loader.ts, cli.ts) because @axlsdk/eval cannot depend on @axlsdk/studio.\n * Keep in sync with the studio versions if either changes.\n */\n\nimport { resolve } from 'node:path';\nimport { existsSync } from 'node:fs';\nimport { pathToFileURL } from 'node:url';\n\n// ── Config auto-detection ──────────────────────────────────────────\n\nexport const CONFIG_CANDIDATES = [\n 'axl.config.mts',\n 'axl.config.ts',\n 'axl.config.mjs',\n 'axl.config.js',\n];\n\nexport function findConfig(cwd: string): string | undefined {\n for (const name of CONFIG_CANDIDATES) {\n const p = resolve(cwd, name);\n if (existsSync(p)) return p;\n }\n return undefined;\n}\n\n// ── Extension helpers ──────────────────────────────────────────────\n\n/** Returns true if the file is TypeScript and needs tsx to load. */\nexport function needsTsxLoader(filePath: string): boolean {\n return /\\.[mc]?tsx?$/.test(filePath);\n}\n\n// ── Runtime resolution ─────────────────────────────────────────────\n\n/**\n * Resolve the AxlRuntime from a dynamically imported config module.\n *\n * Module shapes handled:\n * - ESM `export default runtime` → mod.default is the runtime\n * - CJS compiled from `export default runtime` → mod.default.default is the runtime\n * - CJS `module.exports = runtime` → mod.default is the runtime\n * - Named `export { runtime }` → mod.runtime is the runtime\n */\nexport function resolveRuntime(mod: Record<string, any>): unknown {\n const def = mod.default as Record<string, any> | undefined;\n return def?.default ?? def ?? mod.runtime;\n}\n\n// ── Module loading ────────────────────────────────────────────────\n\n// Lazily resolved tsImport function from tsx. `undefined` = not yet checked,\n// `null` = tsx not available.\nlet tsImportFn:\n | ((specifier: string, parentURL: string) => Promise<Record<string, any>>)\n | null\n | undefined;\n\n/**\n * Import a module, using tsx's `tsImport()` for TypeScript files.\n *\n * `tsImport()` handles ESM/CJS format correctly without process-wide side effects —\n * no need for `register()` hooks or ESM-forcing workarounds. Falls back to regular\n * `import()` for non-TypeScript files or when tsx is not installed.\n */\nexport async function importModule(\n filePath: string,\n parentURL: string,\n): Promise<Record<string, any>> {\n if (needsTsxLoader(filePath)) {\n if (tsImportFn === undefined) {\n try {\n // @ts-expect-error — tsx is an optional runtime dependency\n const mod = await import('tsx/esm/api');\n tsImportFn = mod.tsImport ?? null;\n } catch {\n tsImportFn = null;\n console.warn(\n '[axl-eval] Warning: tsx is not installed. TypeScript files require tsx.\\n' +\n ' Install it with: npm install -D tsx',\n );\n }\n }\n if (tsImportFn) {\n return (await tsImportFn(pathToFileURL(filePath).href, parentURL)) as Record<string, any>;\n }\n }\n return await import(pathToFileURL(filePath).href);\n}\n\n// ── Conditions ────────────────────────────────────────────────────\n\nexport async function registerConditions(conditions: string[]): Promise<void> {\n try {\n const nodeModule = await import('node:module');\n const hookCode = [\n `const extra = ${JSON.stringify(conditions)};`,\n `export async function resolve(specifier, context, nextResolve) {`,\n ` return nextResolve(specifier, {`,\n ` ...context,`,\n ` conditions: [...new Set([...context.conditions, ...extra])],`,\n ` });`,\n `}`,\n ].join('\\n');\n nodeModule.register(`data:text/javascript,${encodeURIComponent(hookCode)}`);\n } catch {\n console.warn('[axl-eval] Warning: --conditions requires Node.js 20.6+');\n }\n}\n"],"mappings":";;;;;;;;;AAEA,SAAS,aAAa,gBAAgB;AACtC,SAAS,YAAY,eAAe,aAAa,gBAAgB,aAAa;AAC9E,YAAY,UAAU;;;ACItB,SAAS,eAAe;AACxB,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAIvB,IAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,WAAW,KAAiC;AAC1D,aAAW,QAAQ,mBAAmB;AACpC,UAAM,IAAI,QAAQ,KAAK,IAAI;AAC3B,QAAI,WAAW,CAAC,EAAG,QAAO;AAAA,EAC5B;AACA,SAAO;AACT;AAKO,SAAS,eAAe,UAA2B;AACxD,SAAO,eAAe,KAAK,QAAQ;AACrC;AAaO,SAAS,eA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AAAA,QACrF;AAAA,MACF;AAAA,IACF;AAEA,QAAI,cAAc,QAAQ,SAAS,GAAG;AACpC,YAAM,SAAS,QAAQ,WAAW,IAAI,QAAQ,CAAC,IAAI;AACnD,YAAM,YAAiB,aAAa,aAAQ,UAAU,CAAC;AACvD,YAAM,MAAM,WAAW,EAAE,WAAW,KAAK,CAAC;AAC1C,YAAM,eAAe,YAAY,KAAK,UAAU,QAAQ,MAAM,CAAC,GAAG,OAAO;AACzE,cAAQ,IAAI,oBAAoB,UAAU,EAAE;AAAA,IAC9C;AAAA,EACF,UAAE;AACA,UAAM,QAAQ,SAAS,EAAE,MAAM,MAAM;AAAA,IAAC,CAAC;AAAA,EACzC;AAGA,MAAI,QAAQ,WAAW,GAAG;AACxB,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;AAEA,KAAK,EAAE,MAAM,CAAC,QAAQ;AACpB,UAAQ,MAAM,GAAG;AACjB,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts","../src/cli-utils.ts","../src/cli-validate.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { readdirSync, statSync } from 'node:fs';\nimport { readFile as readFileAsync, writeFile as writeFileAsync, mkdir } from 'node:fs/promises';\nimport * as path from 'node:path';\nimport type { AxlRuntime, EvalExecuteWorkflow } from '@axlsdk/axl';\nimport { evalCompare } from './compare.js';\nimport { runEval } from './runner.js';\nimport { rescore } from './rescore.js';\nimport { aggregateRuns } from './multi-run.js';\nimport type { MultiRunSummary } from './multi-run.js';\nimport type { EvalConfig, EvalResult } from './types.js';\nimport {\n findConfig,\n resolveRuntime,\n importModule,\n registerConditions,\n pickDefault,\n pickExport,\n expandGlob,\n CONFIG_CANDIDATES,\n} from './cli-utils.js';\nimport { validateEvalConfig } from './cli-validate.js';\n\nconst KNOWN_FLAGS = new Set([\n '--output',\n '--config',\n '--conditions',\n '--fail-on-regression',\n '--threshold',\n '--runs',\n '--capture-traces',\n]);\n\nasync function main() {\n const args = process.argv.slice(2);\n\n if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {\n console.log(`\nUsage:\n axl-eval <path> Run eval file(s)\n axl-eval <path> --runs <n> Run eval N times (multi-run)\n axl-eval <path> --output <file> Save results to JSON\n axl-eval <path> --config <file> Use config file for runtime\n axl-eval <path> --conditions <list> Node.js import conditions (comma-separated)\n axl-eval <path> --capture-traces Populate EvalItem.traces on every item\n (success + failure). Adds memory\n overhead proportional to dataset size\n x turns x agents; off by default.\n axl-eval rescore <results> <eval-file> Re-run scorers on saved outputs\n axl-eval compare <a> <b> Compare two eval result files\n axl-eval compare <a> <b> --threshold <v> Set regression threshold (global or per-scorer)\n axl-eval compare <a> <b> --fail-on-regression Exit 1 if regressions\n\nConfig auto-detection (when --config is not specified):\n ${CONFIG_CANDIDATES.join(' -> ')}\n\nWhen a config is found, the exported AxlRuntime is passed to executeWorkflow\nand cost is tracked automatically via runtime.trackCost().\nWhen no config is found, a bare AxlRuntime is created (providers from env vars).\n`);\n process.exit(0);\n }\n\n if (args[0] === 'compare') {\n await runCompare(args.slice(1));\n return;\n }\n\n if (args[0] === 'rescore') {\n await runRescore(args.slice(1));\n return;\n }\n\n await runEvalCommand(args);\n}\n\nfunction parseThresholdArg(args: string[]): Record<string, number> | number | undefined {\n const idx = args.indexOf('--threshold');\n if (idx === -1 || idx + 1 >= args.length) return undefined;\n const value = args[idx + 1];\n\n // Global numeric threshold: --threshold 0.05\n if (/^[\\d.]+$/.test(value)) return parseFloat(value);\n\n // Per-scorer map: --threshold accuracy=0,tone=0.1\n const map: Record<string, number> = {};\n for (const pair of value.split(',')) {\n const [key, val] = pair.split('=');\n if (key && val != null) map[key.trim()] = parseFloat(val.trim());\n }\n return Object.keys(map).length > 0 ? map : undefined;\n}\n\nasync function runCompare(args: string[]) {\n const failOnRegression = args.includes('--fail-on-regression');\n const thresholds = parseThresholdArg(args);\n const files = args.filter(\n (a, i) => !a.startsWith('--') && !(i > 0 && args[i - 1] === '--threshold'),\n );\n\n if (files.length !== 2) {\n console.error('Usage: axl-eval compare <baseline.json> <candidate.json> [--threshold <value>]');\n process.exit(1);\n }\n\n const baselineRaw = JSON.parse(await readFileAsync(files[0], 'utf-8'));\n const candidateRaw = JSON.parse(await readFileAsync(files[1], 'utf-8'));\n const baseline: EvalResult | EvalResult[] = baselineRaw;\n const candidate: EvalResult | EvalResult[] = candidateRaw;\n const compareOptions = thresholds != null ? { thresholds } : undefined;\n const comparison = evalCompare(baseline, candidate, compareOptions);\n\n console.log(\n `\\nCompare: baseline (${comparison.baseline.id.slice(0, 8)}) -> candidate (${comparison.candidate.id.slice(0, 8)})\\n`,\n );\n\n const scorerNames = Object.keys(comparison.scorers);\n const maxNameLen = Math.max(...scorerNames.map((n) => n.length), 6);\n const hasCI = scorerNames.some((n) => comparison.scorers[n].ci != null);\n\n const ciHeader = hasCI ? ' CI 95% Sig' : '';\n const ciRule = hasCI ? ' ---------------- ---' : '';\n console.log(` ${'Scorer'.padEnd(maxNameLen)} Baseline Candidate Delta Change${ciHeader}`);\n console.log(` ${''.padEnd(maxNameLen, '-')} -------- --------- -------- ------${ciRule}`);\n\n for (const name of scorerNames) {\n const s = comparison.scorers[name];\n const sign = s.delta > 0 ? '+' : '';\n let line = ` ${name.padEnd(maxNameLen)} ${s.baselineMean.toFixed(3).padStart(8)} ${s.candidateMean.toFixed(3).padStart(9)} ${(sign + s.delta.toFixed(3)).padStart(8)} ${(sign + s.deltaPercent.toFixed(1) + '%').padStart(6)}`;\n if (hasCI) {\n if (s.ci) {\n const lo = (s.ci.lower >= 0 ? '+' : '') + s.ci.lower.toFixed(4);\n const hi = (s.ci.upper >= 0 ? '+' : '') + s.ci.upper.toFixed(4);\n const sig = s.significant ? ' *' : ' ';\n line += ` [${lo}, ${hi}]${sig}`;\n } else {\n line += ' —'.padEnd(22);\n }\n }\n console.log(line);\n }\n\n if (comparison.timing) {\n const t = comparison.timing;\n const sign = t.delta > 0 ? '+' : '';\n console.log(\n `\\n Timing: baseline ${(t.baselineMean / 1000).toFixed(2)}s -> candidate ${(t.candidateMean / 1000).toFixed(2)}s (${sign}${t.deltaPercent.toFixed(1)}%)`,\n );\n }\n if (comparison.cost) {\n const c = comparison.cost;\n const sign = c.delta > 0 ? '+' : '';\n console.log(\n ` Cost: baseline $${c.baselineTotal.toFixed(2)} -> candidate $${c.candidateTotal.toFixed(2)} (${sign}${c.deltaPercent.toFixed(1)}%)`,\n );\n }\n\n const baselineRef = Array.isArray(baseline) ? baseline[0] : baseline;\n const stable = Math.max(\n 0,\n baselineRef.items.length - comparison.regressions.length - comparison.improvements.length,\n );\n console.log(\n `\\n Regressions: ${comparison.regressions.length} | Improvements: ${comparison.improvements.length} | Stable: ${stable}\\n`,\n );\n\n if (failOnRegression && comparison.regressions.length > 0) {\n // When CI is available, only fail on significant regressions\n const hasSignificance = scorerNames.some((n) => comparison.scorers[n].significant != null);\n if (hasSignificance) {\n const hasSignificantRegression = scorerNames.some(\n (n) => comparison.scorers[n].significant === true && comparison.scorers[n].delta < 0,\n );\n if (hasSignificantRegression) process.exit(1);\n } else {\n process.exit(1);\n }\n }\n}\n\nasync function runRescore(args: string[]) {\n const { outputPath, configArg, conditions, paths } = parseEvalArgs(args);\n\n if (paths.length < 2) {\n console.error('Usage: axl-eval rescore <results.json> <eval-file> [--output <file>]');\n process.exit(1);\n }\n\n const [resultsPath, evalFilePath] = paths;\n const raw = JSON.parse(await readFileAsync(resultsPath, 'utf-8'));\n const results: EvalResult[] = Array.isArray(raw) ? raw : [raw];\n\n const runtime = await getRuntime(configArg, conditions);\n try {\n const mod = await importModule(path.resolve(evalFilePath), import.meta.url);\n const evalConfig = pickDefault<EvalConfig>(mod);\n\n if (!evalConfig || typeof evalConfig !== 'object') {\n console.error(\n `Error: ${evalFilePath} does not export an eval config object — got ${evalConfig === null ? 'null' : typeof evalConfig}.`,\n );\n process.exit(1);\n }\n if (!Array.isArray(evalConfig.scorers) || evalConfig.scorers.length === 0) {\n console.error(`Error: ${evalFilePath} does not export a non-empty scorers array.`);\n process.exit(1);\n }\n\n const rescored: EvalResult[] = [];\n for (const resultData of results) {\n rescored.push(await rescore(resultData, evalConfig.scorers, runtime));\n }\n\n for (const r of rescored) {\n console.log('\\n' + formatTable(r) + '\\n');\n }\n\n if (outputPath) {\n const output = Array.isArray(raw) ? rescored : rescored[0];\n const outputDir = path.dirname(path.resolve(outputPath));\n await mkdir(outputDir, { recursive: true });\n await writeFileAsync(outputPath, JSON.stringify(output, null, 2), 'utf-8');\n console.log(`Rescored results saved to ${outputPath}`);\n }\n } finally {\n await runtime.shutdown().catch(() => {});\n }\n}\n\n/**\n * Resolve a CLI path argument into a list of eval files.\n *\n * Accepts:\n * - An explicit file path (`path/to/foo.eval.ts`)\n * - A directory (lists `*.eval.[mc]?[jt]sx?` inside, non-recursive)\n * - A glob pattern: `evals/*.eval.ts`, `evals/**\\/*.eval.ts`, `**\\/*.eval.ts`\n *\n * Glob expansion mirrors the studio eval-loader's so users get the same\n * behavior in both places. Without it, users running on Windows or with\n * quoted patterns hit confusing \"file not found\" errors when the shell\n * couldn't expand the glob.\n */\nfunction collectEvalFiles(p: string): string[] {\n if (p.includes('*')) return expandGlob(p, process.cwd());\n const resolved = path.resolve(p);\n try {\n const stat = statSync(resolved);\n if (stat.isDirectory()) {\n const entries = readdirSync(resolved);\n return entries\n .filter((e) => /\\.eval\\.[mc]?[jt]sx?$/.test(e))\n .map((e) => path.join(resolved, e));\n }\n return [resolved];\n } catch {\n return [resolved];\n }\n}\n\n/** Render observed workflows for a terse header line. Multiple → comma-separated. */\nfunction formatWorkflows(workflows: unknown): string {\n if (!Array.isArray(workflows) || workflows.length === 0) return '(unknown)';\n return (workflows as unknown[]).filter((w): w is string => typeof w === 'string').join(', ');\n}\n\nfunction formatTable(result: EvalResult): string {\n const lines: string[] = [];\n const scorerNames = Object.keys(result.summary.scorers);\n const maxNameLen = Math.max(...scorerNames.map((n) => n.length), 'Scorer'.length);\n const colWidth = 8;\n\n lines.push(\n `Eval: ${formatWorkflows(result.metadata.workflows)} x ${result.dataset} (${result.summary.count} items)`,\n );\n lines.push(\n ` ${'Scorer'.padEnd(maxNameLen)} ${'Mean'.padStart(colWidth)} ${'Min'.padStart(colWidth)} ${'Max'.padStart(colWidth)} ${'p50'.padStart(colWidth)} ${'p95'.padStart(colWidth)}`,\n );\n\n const ruleLen = maxNameLen + 2 + (colWidth + 2) * 5;\n lines.push(' ' + '\\u2500'.repeat(ruleLen));\n\n for (const name of scorerNames) {\n const s = result.summary.scorers[name];\n // Detect scorers with no valid scores (all items errored → computeStats([]) → all zeros)\n const validScoreCount = result.items.filter((i) => !i.error && i.scores[name] != null).length;\n if (validScoreCount === 0) {\n lines.push(\n ` ${name.padEnd(maxNameLen)} ${'--'.padStart(colWidth)} ${'--'.padStart(colWidth)} ${'--'.padStart(colWidth)} ${'--'.padStart(colWidth)} ${'--'.padStart(colWidth)}`,\n );\n } else {\n lines.push(\n ` ${name.padEnd(maxNameLen)} ${s.mean.toFixed(2).padStart(colWidth)} ${s.min.toFixed(2).padStart(colWidth)} ${s.max.toFixed(2).padStart(colWidth)} ${s.p50.toFixed(2).padStart(colWidth)} ${s.p95.toFixed(2).padStart(colWidth)}`,\n );\n }\n }\n\n if (result.summary.timing) {\n const t = result.summary.timing;\n lines.push(\n ` ${'Timing'.padEnd(maxNameLen)} ${(t.mean / 1000).toFixed(2).padStart(colWidth)}s ${(t.p50 / 1000).toFixed(2).padStart(colWidth)}s ${(t.p95 / 1000).toFixed(2).padStart(colWidth)}s`,\n );\n }\n\n const durationSec = (result.duration / 1000).toFixed(1);\n const costStr = result.totalCost > 0 ? `$${result.totalCost.toFixed(2)}` : '$0.00';\n lines.push('');\n lines.push(\n ` Failures: ${result.summary.failures}/${result.summary.count} | Cost: ${costStr} | Duration: ${durationSec}s`,\n );\n\n const itemsWithErrors = result.items.filter((i) => i.scorerErrors?.length);\n if (itemsWithErrors.length > 0) {\n const uniqueErrors = [...new Set(itemsWithErrors.flatMap((i) => i.scorerErrors!))];\n lines.push('');\n lines.push(\n ` Scorer errors (${itemsWithErrors.length}/${result.summary.count} items affected):`,\n );\n for (const err of uniqueErrors.slice(0, 5)) {\n lines.push(` - ${err}`);\n }\n if (uniqueErrors.length > 5) {\n lines.push(` ... and ${uniqueErrors.length - 5} more`);\n }\n }\n\n return lines.join('\\n');\n}\n\nfunction formatMultiRunTable(summary: MultiRunSummary): string {\n const lines: string[] = [];\n const scorerNames = Object.keys(summary.scorers);\n const maxNameLen = Math.max(...scorerNames.map((n) => n.length), 'Scorer'.length);\n const colWidth = 16;\n\n lines.push(\n `Eval: ${formatWorkflows(summary.workflows)} x ${summary.dataset} \\u2014 ${summary.runCount} runs`,\n );\n lines.push(\n ` ${'Scorer'.padEnd(maxNameLen)} ${'Mean \\u00b1 Std'.padStart(colWidth)} ${'Min'.padStart(8)} ${'Max'.padStart(8)}`,\n );\n const ruleLen = maxNameLen + 2 + colWidth + 2 + 8 + 2 + 8;\n lines.push(' ' + '\\u2500'.repeat(ruleLen));\n\n for (const name of scorerNames) {\n const s = summary.scorers[name];\n const meanStd = `${s.mean.toFixed(3)} \\u00b1 ${s.std.toFixed(3)}`;\n lines.push(\n ` ${name.padEnd(maxNameLen)} ${meanStd.padStart(colWidth)} ${s.min.toFixed(3).padStart(8)} ${s.max.toFixed(3).padStart(8)}`,\n );\n }\n\n if (summary.timing) {\n lines.push(\n ` ${'Timing'.padEnd(maxNameLen)} ${((summary.timing.mean / 1000).toFixed(2) + ' \\u00b1 ' + (summary.timing.std / 1000).toFixed(2) + 's').padStart(colWidth)}`,\n );\n }\n\n const costStr = summary.totalCost > 0 ? `$${summary.totalCost.toFixed(2)}` : '$0.00';\n const durationStr = (summary.totalDuration / 1000).toFixed(1);\n lines.push('');\n lines.push(` Total Cost: ${costStr} | Total Duration: ${durationStr}s`);\n\n return lines.join('\\n');\n}\n\n// ── Runtime resolution ─────────────────────────────────────────────\n\nasync function resolveRuntimeFromConfig(configPath: string): Promise<AxlRuntime> {\n try {\n const mod = await importModule(configPath, import.meta.url);\n const runtime = resolveRuntime(mod) as AxlRuntime;\n\n if (!runtime || typeof runtime.execute !== 'function') {\n console.error(`Config must export a default AxlRuntime instance.`);\n if (runtime) {\n const keys = Object.keys(runtime as object)\n .slice(0, 5)\n .join(', ');\n console.error(` Got: ${typeof runtime}${keys ? ` with keys: { ${keys} }` : ''}`);\n }\n console.error(\n `Example:\\n import { AxlRuntime } from '@axlsdk/axl';\\n export default new AxlRuntime({ ... });`,\n );\n process.exit(1);\n }\n\n return runtime;\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n if (\n /Cannot use import statement|Unexpected reserved word|top-level await|exports is not defined/.test(\n msg,\n )\n ) {\n const ext = path.extname(configPath);\n console.error(`[axl-eval] Config failed to load due to a CJS/ESM compatibility issue.`);\n if (ext === '.ts' || ext === '.tsx') {\n console.error(\n ` Tip: try renaming to .mts to force ESM format, or ensure tsx is installed and up to date.`,\n );\n } else {\n console.error(` Tip: add \"type\": \"module\" to your package.json.`);\n }\n console.error();\n }\n console.error(`Failed to load config:`, err);\n process.exit(1);\n }\n}\n\nasync function getRuntime(configArg?: string, conditions?: string[]): Promise<AxlRuntime> {\n // Register import conditions before any config loading\n if (conditions && conditions.length > 0) {\n await registerConditions(conditions);\n }\n\n // 1. Explicit --config\n if (configArg) {\n const configPath = path.resolve(process.cwd(), configArg);\n const stat = statSync(configPath, { throwIfNoEntry: false });\n if (!stat?.isFile()) {\n console.error(`Config file not found: ${configPath}`);\n process.exit(1);\n }\n console.error(`[axl-eval] Loading config from ${configPath}`);\n return resolveRuntimeFromConfig(configPath);\n }\n\n // 2. Auto-detect\n const found = findConfig(process.cwd());\n if (found) {\n console.error(`[axl-eval] Auto-detected config: ${found}`);\n return resolveRuntimeFromConfig(found);\n }\n\n // 3. Bare runtime (providers from env vars)\n const { AxlRuntime } = await import('@axlsdk/axl');\n return new AxlRuntime();\n}\n\n// ── Arg parsing ────────────────────────────────────────────────────\n\nfunction parseEvalArgs(args: string[]): {\n outputPath?: string;\n configArg?: string;\n conditions: string[];\n runs: number;\n captureTraces: boolean;\n paths: string[];\n} {\n let outputPath: string | undefined;\n let configArg: string | undefined;\n let conditions: string[] = [];\n let runs = 1;\n let captureTraces = false;\n const paths: string[] = [];\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (arg === '--output' || arg === '--config' || arg === '--conditions' || arg === '--runs') {\n if (i + 1 >= args.length) {\n console.error(`Error: ${arg} requires a value`);\n process.exit(1);\n }\n const value = args[++i];\n if (arg === '--output') outputPath = value;\n else if (arg === '--config') configArg = value;\n else if (arg === '--runs') runs = Math.max(1, parseInt(value, 10) || 1);\n else\n conditions = value\n .split(',')\n .map((c) => c.trim())\n .filter(Boolean);\n } else if (arg === '--capture-traces') {\n // Boolean flag — no value consumed.\n captureTraces = true;\n } else if (arg.startsWith('--')) {\n if (!KNOWN_FLAGS.has(arg)) {\n console.error(`Unknown flag: ${arg}`);\n process.exit(1);\n }\n } else {\n paths.push(arg);\n }\n }\n\n return { outputPath, configArg, conditions, runs, captureTraces, paths };\n}\n\n// ── Main eval command ──────────────────────────────────────────────\n\nasync function runEvalCommand(args: string[]) {\n const { outputPath, configArg, conditions, runs, captureTraces, paths } = parseEvalArgs(args);\n\n if (paths.length === 0) {\n console.error('Error: No eval file path provided');\n process.exit(1);\n }\n\n const evalFiles: string[] = [];\n for (const p of paths) {\n evalFiles.push(...collectEvalFiles(p));\n }\n\n if (evalFiles.length === 0) {\n console.error('Error: No eval files found');\n process.exit(1);\n }\n\n const runtime = await getRuntime(configArg, conditions);\n const results: EvalResult[] = [];\n let failedFiles = 0;\n\n try {\n for (const filePath of evalFiles) {\n try {\n const mod = await importModule(path.resolve(filePath), import.meta.url);\n const evalConfig = pickDefault<EvalConfig>(mod);\n\n const validationError = validateEvalConfig(evalConfig);\n if (validationError) {\n console.error(`Error: ${filePath} ${validationError}`);\n failedFiles++;\n continue;\n }\n\n // Resolve executeWorkflow: custom export > registered workflow > error\n // Walk the ESM/CJS interop chain symmetrically with the default export\n // so named exports stay visible when tsx loads the eval module as CJS.\n const exported = pickExport<unknown>(mod, 'executeWorkflow');\n\n // Validate that the export, if present, is callable. Catches the\n // `export const executeWorkflow = 'foo'` typo at the boundary instead\n // of crashing deep inside trackExecution with a confusing stack.\n let customExecute: EvalExecuteWorkflow | undefined;\n if (typeof exported === 'function') {\n customExecute = exported as EvalExecuteWorkflow;\n } else if (exported !== undefined) {\n console.error(\n `[axl-eval] Error: ${filePath} exports executeWorkflow but it is ${typeof exported}, not a function.`,\n );\n failedFiles++;\n continue;\n }\n\n let executeWorkflow: EvalExecuteWorkflow;\n\n if (customExecute) {\n // Wrap custom executeWorkflow with trackExecution for cost + metadata attribution\n executeWorkflow = async (input, rt) => {\n const {\n result,\n cost: trackedCost,\n metadata,\n } = await runtime.trackExecution(async () => {\n return customExecute(input, rt);\n });\n return {\n output: result.output,\n cost: result.cost ?? trackedCost,\n metadata: result.metadata ?? metadata,\n };\n };\n } else if (runtime.getWorkflow(evalConfig.workflow)) {\n // No executeWorkflow exported but workflow is registered — use runtime.execute()\n executeWorkflow = async (input) => {\n const { result, cost, metadata } = await runtime.trackExecution(async () => {\n return runtime.execute(evalConfig.workflow, input);\n });\n return { output: result, cost, metadata };\n };\n } else {\n // Fail loudly. The previous identity-passthrough fallback silently\n // produced all-zero scores in CI — exactly the kind of footgun the\n // \"fail loudly, not silently\" rule is meant to prevent. If you\n // genuinely want identity, export it explicitly:\n // export const executeWorkflow = async (input) => ({ output: input });\n //\n // Surface what WAS exported (top-level + .default) so users\n // recognize a typo like `execute_workflow` and can spot the\n // CJS-interop case that motivates this whole code path: when tsx\n // loads a `.ts` file as CJS, all named exports land on\n // `mod.default.<name>`. The chain walk above already handled this,\n // but a user who removed `executeWorkflow` will see exactly what\n // export names ARE present.\n const exportShape = (() => {\n const top = Object.keys(mod).filter((k) => k !== 'default');\n const fromDefault =\n mod.default && typeof mod.default === 'object'\n ? Object.keys(mod.default as Record<string, unknown>)\n : [];\n const all = [...new Set([...top, ...fromDefault])];\n return all.length > 0 ? `Found exports: [${all.join(', ')}].` : '';\n })();\n console.error(\n `[axl-eval] Error: ${filePath} does not export an executeWorkflow function ` +\n `and no workflow named \"${evalConfig.workflow}\" is registered on the runtime.\\n` +\n (exportShape ? ` ${exportShape}\\n` : '') +\n ` Add either:\\n` +\n ` export async function executeWorkflow(input, runtime) { ... }\\n` +\n ` or register the workflow on your runtime via runtime.registerWorkflow(workflow).\\n` +\n ` Tip: if your eval previously worked, your package.json may be missing\\n` +\n ` \"type\": \"module\" — tsx loads .ts as CJS, putting named exports on\\n` +\n ` mod.default.<name>. The CLI handles that interop, but if you renamed\\n` +\n ` or removed the export the file path is your fix.`,\n );\n failedFiles++;\n continue;\n }\n\n // When --capture-traces is set, forward it to runEval so the runner\n // wraps each item's execution in a nested trackExecution({ captureTraces: true }).\n // This populates EvalItem.traces on both success (via tracked.traces)\n // and failure (via the axlCapturedTraces side-channel on the thrown\n // error). Nested trackExecution scopes walk the AsyncLocalStorage\n // parent chain, so the outer trackExecution above still observes\n // cost/metadata correctly.\n const runOptions = captureTraces ? { captureTraces: true } : undefined;\n\n if (runs > 1) {\n // Multi-run mode. Buffer per-run results locally so we can mark the\n // batch correctly before committing to outer `results[]`. The\n // original bug was the opposite: results pushed eagerly per-run, a\n // throw mid-batch left partial results posing as a complete run\n // (no `fromPartialBatch` marker, aggregate never ran). The fix ISN'T\n // to throw the partials away — those runs cost money and have\n // statistical signal. Instead we preserve them with explicit\n // partial-batch metadata, aggregate over what completed, and exit\n // non-zero so CI knows the batch wasn't clean.\n const { randomUUID } = await import('node:crypto');\n const runGroupId = randomUUID();\n const runResults: EvalResult[] = [];\n let runFailure: Error | undefined;\n\n for (let r = 0; r < runs; r++) {\n console.error(`[axl-eval] Run ${r + 1}/${runs}...`);\n try {\n const result = await runEval(evalConfig, executeWorkflow, runtime, runOptions);\n result.metadata.runGroupId = runGroupId;\n result.metadata.runIndex = r;\n runResults.push(result);\n } catch (err) {\n runFailure = err instanceof Error ? err : new Error(String(err));\n console.error(`[axl-eval] Run ${r + 1}/${runs} failed: ${runFailure.message}`);\n // Stop attempting further runs — we don't know whether this is\n // transient (rate limit) or permanent (auth failure), and\n // burning more API calls speculatively is hostile. Preserve\n // what completed.\n break;\n }\n }\n\n if (runResults.length === 0) {\n // Nothing completed — surface as a per-file failure. No partial\n // artifact to write; the outer try/catch error message would\n // duplicate the \"Run 1/N failed\" line we already printed, so\n // increment and continue without re-throwing.\n console.error(\n `[axl-eval] Aborting ${filePath}: no runs completed (${runFailure?.message ?? 'unknown failure'}).`,\n );\n failedFiles++;\n continue;\n }\n\n const partial = runResults.length < runs;\n if (partial) {\n // Mark every completed run so any consumer reading\n // `result.metadata` sees the partial-batch context. `aggregateRuns`\n // computes statistics over `runResults.length`, which is the\n // honest sample size to report.\n //\n // The flag is `fromPartialBatch` — a per-run marker meaning\n // \"this run came from a batch that did not complete.\" It is\n // NOT named `partialBatch` because that read as \"this run is\n // partial,\" and a defensive consumer wrote\n // `if (run.metadata.partialBatch) skipThisRun()`, throwing\n // away successful work that cost real money. The flag describes\n // the BATCH the run belongs to, not the run itself.\n //\n // `runFailure?.message` can be empty (e.g. `new Error('')` from a\n // misbehaving provider); fall back to `String(runFailure)` so the\n // banner never renders a blank \"Stopped after:\" line. Skip the\n // field entirely if both are empty so `buildMultiRunResult`'s\n // empty-string filter doesn't have to defensively guess.\n const failureMsg = runFailure\n ? runFailure.message || String(runFailure) || undefined\n : undefined;\n for (const r of runResults) {\n r.metadata.fromPartialBatch = true;\n r.metadata.batchCompleted = runResults.length;\n r.metadata.batchAttempted = runs;\n if (failureMsg) r.metadata.batchFailure = failureMsg;\n }\n console.error(\n `[axl-eval] PARTIAL: ${runResults.length} of ${runs} runs completed for ${filePath}.`,\n );\n failedFiles++;\n }\n\n const summary = aggregateRuns(runResults);\n console.log('\\n' + formatMultiRunTable(summary) + '\\n');\n for (const r of runResults) results.push(r);\n } else {\n const result = await runEval(evalConfig, executeWorkflow, runtime, runOptions);\n results.push(result);\n\n console.log('\\n' + formatTable(result) + '\\n');\n }\n } catch (err) {\n console.error(\n `Error running eval ${filePath}: ${err instanceof Error ? err.message : String(err)}`,\n );\n failedFiles++;\n }\n }\n\n if (outputPath && results.length > 0) {\n const output = results.length === 1 ? results[0] : results;\n const outputDir = path.dirname(path.resolve(outputPath));\n await mkdir(outputDir, { recursive: true });\n await writeFileAsync(outputPath, JSON.stringify(output, null, 2), 'utf-8');\n console.log(`Results saved to ${outputPath}`);\n }\n } finally {\n await runtime.shutdown().catch(() => {});\n }\n\n // Exit non-zero if any eval file failed to load/run. Previously we only\n // exited non-zero when zero evals succeeded, which silently masked\n // misconfigured files in mixed-success runs (a CI footgun).\n if (failedFiles > 0 || results.length === 0) {\n process.exit(1);\n }\n}\n\nmain().catch((err) => {\n console.error(err);\n process.exit(1);\n});\n","/**\n * CLI utilities for `axl-eval`.\n *\n * The actual implementations of the loader, glob, and config-detection\n * helpers live in `@axlsdk/axl`'s `cli-internals` so a fix to (e.g.) the\n * tsx loader registration applies to both axl-eval and axl-studio\n * atomically. This file is now a thin re-export plus the symmetric\n * module-resolution helpers from `@axlsdk/axl`.\n */\n\nexport {\n resolveRuntime,\n pickDefault,\n pickExport,\n CONFIG_CANDIDATES,\n findConfig,\n needsTsxLoader,\n importModule,\n expandGlob,\n registerConditions,\n} from '@axlsdk/axl';\n","import type { EvalConfig } from './types.js';\n\n/**\n * Validate an eval config's required fields and produce a diagnostic string\n * if invalid. Returns `undefined` when the config passes.\n *\n * Returns a single-line message tail (caller prepends the file path) so the\n * full error reads like: `Error: <file> <message>`.\n *\n * Goes beyond a falsy check to:\n * - catch `scorers: []` which previously silently ran with no scorers\n * - reject scorers arrays that contain non-callable entries (e.g. typo\n * `scorers: [null, undefined]` would crash deep inside `runEval`)\n * - reject non-string `workflow` (downstream `runtime.getWorkflow(...)`\n * would silently miss it)\n * - reject non-object `dataset` (must be a `dataset()` factory result)\n * - provide a `Got: { keys: [...] }` hint so users can spot typos like\n * `scorerS` vs `scorers` immediately\n *\n * Lives in its own module so unit tests can import it without triggering\n * `cli.ts`'s `main()` at module load time.\n */\nexport function validateEvalConfig(cfg: unknown): string | undefined {\n if (!cfg || typeof cfg !== 'object') {\n return `does not export a valid eval config — got ${cfg === null ? 'null' : typeof cfg}.`;\n }\n const c = cfg as Partial<EvalConfig>;\n const missing: string[] = [];\n if (!c.workflow) missing.push('workflow');\n if (!c.dataset) missing.push('dataset');\n if (!c.scorers) missing.push('scorers');\n\n if (missing.length > 0) {\n const keys = Object.keys(c as object).slice(0, 10);\n const got = keys.length > 0 ? ` Got: { ${keys.join(', ')} }.` : '';\n return `does not export a valid eval config (missing ${missing.join(', ')}).${got}`;\n }\n\n if (typeof c.workflow !== 'string') {\n return `exports a non-string workflow (got ${typeof c.workflow}) — workflow must be the registered workflow name.`;\n }\n if (typeof c.dataset !== 'object' || Array.isArray(c.dataset)) {\n return `exports a non-object dataset (got ${Array.isArray(c.dataset) ? 'array' : typeof c.dataset}) — use the dataset() factory.`;\n }\n if (typeof (c.dataset as { getItems?: unknown }).getItems !== 'function') {\n return `exports a dataset without a getItems() method — use the dataset() factory.`;\n }\n if (!Array.isArray(c.scorers) || c.scorers.length === 0) {\n return `exports an empty scorers array — at least one scorer is required.`;\n }\n const badScorerIdx = c.scorers.findIndex(\n (s) => !s || typeof (s as { score?: unknown }).score !== 'function',\n );\n if (badScorerIdx !== -1) {\n return `exports a scorers array with a non-scorer entry at index ${badScorerIdx} — each scorer must have a score() method (use the scorer() factory).`;\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;AAEA,SAAS,aAAa,gBAAgB;AACtC,SAAS,YAAY,eAAe,aAAa,gBAAgB,aAAa;AAC9E,YAAY,UAAU;;;ACMtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACEA,SAAS,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AG;AACjB,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -542,13 +542,16 @@ function resolveThreshold(scorerName, options, metadata) {
|
|
|
542
542
|
return LEGACY_THRESHOLD;
|
|
543
543
|
}
|
|
544
544
|
function evalCompare(baseline, candidate, options) {
|
|
545
|
-
const
|
|
546
|
-
const
|
|
547
|
-
if (
|
|
545
|
+
const baselineRunsRaw = Array.isArray(baseline) ? baseline : [baseline];
|
|
546
|
+
const candidateRunsRaw = Array.isArray(candidate) ? candidate : [candidate];
|
|
547
|
+
if (baselineRunsRaw.length === 0 || candidateRunsRaw.length === 0) {
|
|
548
548
|
throw new Error("Cannot compare empty eval result arrays");
|
|
549
549
|
}
|
|
550
|
-
const
|
|
551
|
-
const
|
|
550
|
+
const runCount = Math.min(baselineRunsRaw.length, candidateRunsRaw.length);
|
|
551
|
+
const baselineRuns = baselineRunsRaw.slice(0, runCount);
|
|
552
|
+
const candidateRuns = candidateRunsRaw.slice(0, runCount);
|
|
553
|
+
const baselineRef = baselineRunsRaw[0];
|
|
554
|
+
const candidateRef = candidateRunsRaw[0];
|
|
552
555
|
if (baselineRef.dataset !== candidateRef.dataset) {
|
|
553
556
|
throw new Error(
|
|
554
557
|
`Cannot compare evals from different datasets: "${baselineRef.dataset}" vs "${candidateRef.dataset}"`
|
|
@@ -563,7 +566,6 @@ function evalCompare(baseline, candidate, options) {
|
|
|
563
566
|
for (const name of baselineScorerNames) {
|
|
564
567
|
pairedDiffs[name] = [];
|
|
565
568
|
}
|
|
566
|
-
const runCount = Math.min(baselineRuns.length, candidateRuns.length);
|
|
567
569
|
for (let r = 0; r < runCount; r++) {
|
|
568
570
|
const bRun = baselineRuns[r];
|
|
569
571
|
const cRun = candidateRuns[r];
|
|
@@ -700,9 +702,21 @@ function evalCompare(baseline, candidate, options) {
|
|
|
700
702
|
parts.push(`${Math.abs(cost.deltaPercent).toFixed(0)}% ${dir}`);
|
|
701
703
|
}
|
|
702
704
|
const summaryStr = `candidate ${parts.length > 0 ? parts.join(", ") : "no meaningful changes"} with ${regressions.length} regressions and ${improvements.length} improvements`;
|
|
705
|
+
const baselinePartial = detectPartial(baselineRunsRaw);
|
|
706
|
+
const candidatePartial = detectPartial(candidateRunsRaw);
|
|
703
707
|
return {
|
|
704
|
-
baseline: {
|
|
705
|
-
|
|
708
|
+
baseline: {
|
|
709
|
+
id: baselineRef.id,
|
|
710
|
+
metadata: baselineRef.metadata,
|
|
711
|
+
runCount,
|
|
712
|
+
...baselinePartial ? { partial: baselinePartial } : {}
|
|
713
|
+
},
|
|
714
|
+
candidate: {
|
|
715
|
+
id: candidateRef.id,
|
|
716
|
+
metadata: candidateRef.metadata,
|
|
717
|
+
runCount,
|
|
718
|
+
...candidatePartial ? { partial: candidatePartial } : {}
|
|
719
|
+
},
|
|
706
720
|
scorers,
|
|
707
721
|
timing,
|
|
708
722
|
cost,
|
|
@@ -711,6 +725,20 @@ function evalCompare(baseline, candidate, options) {
|
|
|
711
725
|
summary: summaryStr
|
|
712
726
|
};
|
|
713
727
|
}
|
|
728
|
+
function detectPartial(runs) {
|
|
729
|
+
if (runs.length === 0) return void 0;
|
|
730
|
+
let attempted;
|
|
731
|
+
for (const r of runs) {
|
|
732
|
+
const v = r.metadata?.batchAttempted;
|
|
733
|
+
if (typeof v === "number" && Number.isFinite(v)) {
|
|
734
|
+
attempted = v;
|
|
735
|
+
break;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
if (attempted === void 0) return void 0;
|
|
739
|
+
if (runs.length >= attempted) return void 0;
|
|
740
|
+
return { completed: runs.length, attempted };
|
|
741
|
+
}
|
|
714
742
|
|
|
715
743
|
// src/rescore.ts
|
|
716
744
|
var import_node_crypto2 = require("crypto");
|