@tangle-network/agent-eval 0.121.0 → 0.122.1

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.
@@ -3,7 +3,6 @@ import {
3
3
  assertCodeSurfaceIdentity,
4
4
  campaignBreakdown,
5
5
  campaignMeanComposite,
6
- comparePairedArms,
7
6
  costReceiptFromTCloud,
8
7
  defaultProductionGate,
9
8
  gepaProposer,
@@ -16,7 +15,7 @@ import {
16
15
  runImprovementLoop,
17
16
  surfaceContentHash,
18
17
  surfaceHash
19
- } from "./chunk-32BZXMSO.js";
18
+ } from "./chunk-VZ6VKOJT.js";
20
19
  import {
21
20
  SearchLedgerConflictError,
22
21
  SearchLedgerError,
@@ -60,8 +59,11 @@ import {
60
59
  } from "./chunk-NJC7U437.js";
61
60
  import {
62
61
  eProcess,
62
+ mcnemar,
63
63
  mulberry32,
64
- pairedBootstrap
64
+ pairedBootstrap,
65
+ pairedRiskDifference,
66
+ wilcoxonSignedRank
65
67
  } from "./chunk-PJQFMIOX.js";
66
68
  import {
67
69
  CostAccountingIncompleteError,
@@ -568,6 +570,155 @@ function failureModeRecallJudge(opts = {}) {
568
570
  };
569
571
  }
570
572
 
573
+ // src/paired-arms.ts
574
+ function pairArms(rows, opts) {
575
+ const { baselineArm, treatmentArm } = opts;
576
+ if (baselineArm === treatmentArm) {
577
+ throw new ValidationError(
578
+ `pairArms: baselineArm and treatmentArm are both '${baselineArm}' \u2014 an arm cannot be compared to itself`
579
+ );
580
+ }
581
+ const byArm = /* @__PURE__ */ new Map();
582
+ const armsSeen = /* @__PURE__ */ new Set();
583
+ for (const row of rows) {
584
+ armsSeen.add(row.arm);
585
+ if (row.arm !== baselineArm && row.arm !== treatmentArm) continue;
586
+ const byKey = byArm.get(row.arm) ?? /* @__PURE__ */ new Map();
587
+ const group = byKey.get(row.pairKey) ?? [];
588
+ group.push(row);
589
+ byKey.set(row.pairKey, group);
590
+ byArm.set(row.arm, byKey);
591
+ }
592
+ for (const arm of [baselineArm, treatmentArm]) {
593
+ if (!byArm.has(arm)) {
594
+ const seen = [...armsSeen].sort().join(", ") || "<none>";
595
+ throw new ValidationError(`pairArms: no rows for arm '${arm}' (arms present: ${seen})`);
596
+ }
597
+ }
598
+ const baselineByKey = byArm.get(baselineArm);
599
+ const treatmentByKey = byArm.get(treatmentArm);
600
+ const allKeys = [.../* @__PURE__ */ new Set([...baselineByKey.keys(), ...treatmentByKey.keys()])].sort();
601
+ const pairs = [];
602
+ const unpairedBaseline = [];
603
+ const unpairedTreatment = [];
604
+ for (const pairKey of allKeys) {
605
+ const b = baselineByKey.get(pairKey) ?? [];
606
+ const t = treatmentByKey.get(pairKey) ?? [];
607
+ if (b.length <= 1 && t.length <= 1) {
608
+ if (b.length === 1 && t.length === 1) {
609
+ pairs.push({ pairKey, repIndex: 0, baseline: b[0], treatment: t[0] });
610
+ } else {
611
+ unpairedBaseline.push(...b);
612
+ unpairedTreatment.push(...t);
613
+ }
614
+ continue;
615
+ }
616
+ const bByRep = indexByRepKey(b, pairKey, baselineArm);
617
+ const tByRep = indexByRepKey(t, pairKey, treatmentArm);
618
+ const repKeys = [.../* @__PURE__ */ new Set([...bByRep.keys(), ...tByRep.keys()])].sort();
619
+ let repIndex = 0;
620
+ for (const repKey of repKeys) {
621
+ const baseline = bByRep.get(repKey);
622
+ const treatment = tByRep.get(repKey);
623
+ if (baseline !== void 0 && treatment !== void 0) {
624
+ pairs.push({ pairKey, repIndex: repIndex++, baseline, treatment });
625
+ } else if (baseline !== void 0) {
626
+ unpairedBaseline.push(baseline);
627
+ } else if (treatment !== void 0) {
628
+ unpairedTreatment.push(treatment);
629
+ }
630
+ }
631
+ }
632
+ return { pairs, unpairedBaseline, unpairedTreatment };
633
+ }
634
+ function indexByRepKey(group, pairKey, arm) {
635
+ const byRep = /* @__PURE__ */ new Map();
636
+ for (const row of group) {
637
+ if (row.repKey === void 0) {
638
+ throw new ValidationError(
639
+ `pairArms: pairKey '${pairKey}' has multiple reps in an arm, but a row in arm '${arm}' is missing repKey \u2014 multi-rep items require an explicit repKey on every row so reps pair by identity (pairing reps by outcome or by index would bias the paired statistics)`
640
+ );
641
+ }
642
+ if (byRep.has(row.repKey)) {
643
+ throw new ValidationError(
644
+ `pairArms: duplicate repKey '${row.repKey}' for pairKey '${pairKey}' in arm '${arm}' \u2014 (pairKey, repKey) must uniquely identify a rep within an arm`
645
+ );
646
+ }
647
+ byRep.set(row.repKey, row);
648
+ }
649
+ return byRep;
650
+ }
651
+ function comparePairedArms(rows, opts) {
652
+ const { pairs, unpairedBaseline, unpairedTreatment } = pairArms(rows, opts);
653
+ let correctness = null;
654
+ const baselinePass = [];
655
+ const treatmentPass = [];
656
+ for (const pair of pairs) {
657
+ if (pair.baseline.pass === void 0 || pair.treatment.pass === void 0) continue;
658
+ baselinePass.push(pair.baseline.pass ? 1 : 0);
659
+ treatmentPass.push(pair.treatment.pass ? 1 : 0);
660
+ }
661
+ if (baselinePass.length > 0) {
662
+ const mc = mcnemar(baselinePass, treatmentPass);
663
+ correctness = {
664
+ b10: mc.b,
665
+ b01: mc.c,
666
+ mcnemar: mc,
667
+ riskDifference: pairedRiskDifference(baselinePass, treatmentPass)
668
+ };
669
+ }
670
+ const metricNames = opts.metricNames ?? [
671
+ ...new Set(
672
+ pairs.flatMap((p) => [
673
+ ...Object.keys(p.baseline.metrics ?? {}),
674
+ ...Object.keys(p.treatment.metrics ?? {})
675
+ ])
676
+ )
677
+ ].sort();
678
+ const metricDeltas = metricNames.map((name) => {
679
+ const before = [];
680
+ const after = [];
681
+ let nMissing = 0;
682
+ for (const pair of pairs) {
683
+ const b = metricValue(pair.baseline, name);
684
+ const t = metricValue(pair.treatment, name);
685
+ if (b === void 0 || t === void 0) {
686
+ nMissing++;
687
+ continue;
688
+ }
689
+ before.push(b);
690
+ after.push(t);
691
+ }
692
+ const bootstrapCi = before.length === 0 ? null : pairedBootstrap(before, after, opts.bootstrap);
693
+ return {
694
+ name,
695
+ n: before.length,
696
+ nMissing,
697
+ medianDelta: bootstrapCi === null ? Number.NaN : bootstrapCi.median,
698
+ meanDelta: bootstrapCi === null ? Number.NaN : bootstrapCi.mean,
699
+ bootstrapCi,
700
+ wilcoxon: before.length === 0 ? null : wilcoxonSignedRank(before, after)
701
+ };
702
+ });
703
+ return {
704
+ nPairs: pairs.length,
705
+ nUnpairedBaseline: unpairedBaseline.length,
706
+ nUnpairedTreatment: unpairedTreatment.length,
707
+ correctness,
708
+ metricDeltas
709
+ };
710
+ }
711
+ function metricValue(row, name) {
712
+ const v = row.metrics?.[name];
713
+ if (v === void 0) return void 0;
714
+ if (!Number.isFinite(v)) {
715
+ throw new ValidationError(
716
+ `comparePairedArms: non-finite value for metric '${name}' on pairKey '${row.pairKey}' (arm '${row.arm}'): ${v}`
717
+ );
718
+ }
719
+ return v;
720
+ }
721
+
571
722
  // src/campaign/cross-surface-context.ts
572
723
  function validateCrossSurfaceInput(input) {
573
724
  assertNonEmptyUnique(input.taskOrder, "taskOrder");
@@ -7874,6 +8025,8 @@ function resolveWorktreePath(surface, worktreeDir) {
7874
8025
  }
7875
8026
 
7876
8027
  export {
8028
+ pairArms,
8029
+ comparePairedArms,
7877
8030
  completionVerdict,
7878
8031
  verifyCompletion,
7879
8032
  parseCorrectnessResponse,
@@ -7955,4 +8108,4 @@ export {
7955
8108
  verifyCodeSurface,
7956
8109
  resolveWorktreePath
7957
8110
  };
7958
- //# sourceMappingURL=chunk-JN2FCO5W.js.map
8111
+ //# sourceMappingURL=chunk-TDHX3BVA.js.map