@tangle-network/agent-eval 0.21.0 → 0.22.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +102 -1
  2. package/README.md +4 -0
  3. package/dist/{chunk-WOK2RTWG.js → chunk-4W4NCYM2.js} +134 -109
  4. package/dist/chunk-4W4NCYM2.js.map +1 -0
  5. package/dist/{chunk-WOPGKVN4.js → chunk-6KQG5HAH.js} +2 -2
  6. package/dist/chunk-6M774GY6.js +53 -0
  7. package/dist/chunk-6M774GY6.js.map +1 -0
  8. package/dist/{chunk-3IX6QTB7.js → chunk-IOXMGMHQ.js} +418 -541
  9. package/dist/chunk-IOXMGMHQ.js.map +1 -0
  10. package/dist/{chunk-3GN6U53I.js → chunk-KAO3Q65R.js} +2 -2
  11. package/dist/chunk-QUKKGHTZ.js +121 -0
  12. package/dist/chunk-QUKKGHTZ.js.map +1 -0
  13. package/dist/{chunk-SNUHRBDL.js → chunk-SQQLHODJ.js} +10 -1
  14. package/dist/{chunk-SNUHRBDL.js.map → chunk-SQQLHODJ.js.map} +1 -1
  15. package/dist/chunk-UAND2LOT.js +738 -0
  16. package/dist/chunk-UAND2LOT.js.map +1 -0
  17. package/dist/{chunk-HRZELXCR.js → chunk-USHQBPMH.js} +283 -7
  18. package/dist/chunk-USHQBPMH.js.map +1 -0
  19. package/dist/cli.js +3 -3
  20. package/dist/index.d.ts +10 -284
  21. package/dist/index.js +39 -19
  22. package/dist/index.js.map +1 -1
  23. package/dist/integrity-K2oVlF57.d.ts +210 -0
  24. package/dist/openapi.json +1 -1
  25. package/dist/optimization-UVDNKaO6.d.ts +574 -0
  26. package/dist/optimization.d.ts +6 -144
  27. package/dist/optimization.js +9 -2
  28. package/dist/reporting-B82RSv9C.d.ts +593 -0
  29. package/dist/reporting.d.ts +2 -2
  30. package/dist/reporting.js +15 -8
  31. package/dist/{multi-shot-optimization-Bvtz294B.d.ts → summary-report-D4p7RlDu.d.ts} +381 -1
  32. package/dist/traces.d.ts +101 -181
  33. package/dist/traces.js +16 -5
  34. package/dist/wire/index.js +3 -3
  35. package/docs/research-report-methodology.md +19 -4
  36. package/docs/wire-protocol.md +1 -1
  37. package/package.json +2 -2
  38. package/dist/chunk-3IX6QTB7.js.map +0 -1
  39. package/dist/chunk-HRZELXCR.js.map +0 -1
  40. package/dist/chunk-KRR4VMH7.js +0 -423
  41. package/dist/chunk-KRR4VMH7.js.map +0 -1
  42. package/dist/chunk-WOK2RTWG.js.map +0 -1
  43. package/dist/reporting-Da2ihlcM.d.ts +0 -672
  44. /package/dist/{chunk-WOPGKVN4.js.map → chunk-6KQG5HAH.js.map} +0 -0
  45. /package/dist/{chunk-3GN6U53I.js.map → chunk-KAO3Q65R.js.map} +0 -0
@@ -1,4 +1,5 @@
1
1
  import { a as RunRecord, R as RunSplitTag } from './run-record-CX_jcAyr.js';
2
+ import { a as Run, S as Span, f as TraceEvent, F as FailureClass, T as TraceStore } from './store-u47QaJ9G.js';
2
3
 
3
4
  /**
4
5
  * HeldOutGate — first-class held-out paired-delta promotion gate.
@@ -595,4 +596,383 @@ declare function runMultiShotOptimization<P>(config: MultiShotOptimizationConfig
595
596
  declare function defaultMultiShotObjectives(): Objective<VariantAggregate>[];
596
597
  declare function trialTraceFromMultiShotTrial(trial: MultiShotTrialResult): TrialTrace;
597
598
 
598
- export { type ActionableSideInfo as A, type TrialTrace as B, buildReflectionPrompt as C, DEFAULT_MUTATION_PRIMITIVES as D, type EvolvableVariant as E, crowdingDistance as F, type GateDecision as G, HeldOutGate as H, InMemoryTrialCache as I, defaultMultiShotObjectives as J, dominates as K, paretoFrontier as L, type MutateAdapter as M, paretoFrontierWithCrowding as N, type Objective as O, type ParetoResult as P, parseReflectionResponse as Q, type ReflectionContext as R, type ScenarioAggregate as S, type TrialCache as T, runMultiShotOptimization as U, type VariantAggregate as V, runPromptEvolution as W, scalarScore as X, trialTraceFromMultiShotTrial as Y, type TrialResult as a, type AsiSeverity as b, type Direction as c, type GateEvidence as d, type GenerationReport as e, type HeldOutGateConfig as f, type HeldOutGateRejectionCode as g, type MultiShotGateConfig as h, type MultiShotGateResult as i, type MultiShotMutateAdapter as j, type MultiShotOptimizationConfig as k, type MultiShotOptimizationResult as l, type MultiShotRun as m, type MultiShotRunInput as n, type MultiShotRunner as o, type MultiShotScore as p, type MultiShotScorer as q, type MultiShotSplit as r, type MultiShotTrace as s, type MultiShotTrialResult as t, type MultiShotVariant as u, type PromptEvolutionConfig as v, type PromptEvolutionEvent as w, type PromptEvolutionResult as x, type ReflectionProposal as y, type ScoreAdapter as z };
599
+ /**
600
+ * Failure taxonomy — canonical classes + a default classifier.
601
+ *
602
+ * Every failed run should end up in a named class. The classifier here
603
+ * is rule-based (fast, deterministic); an LLM fallback can be added by
604
+ * the consumer for novel cases and trained into the rule base over time.
605
+ *
606
+ * Consumers call `classifyFailure(run, spans, events)` and persist the
607
+ * returned class as `Run.outcome.failureClass`.
608
+ */
609
+
610
+ interface FailureContext {
611
+ run: Run;
612
+ spans: Span[];
613
+ events: TraceEvent[];
614
+ }
615
+ interface FailureClassification {
616
+ failureClass: FailureClass;
617
+ reason: string;
618
+ triggerSpanId?: string;
619
+ triggerEventId?: string;
620
+ }
621
+ /** Ordered rules — first match wins. */
622
+ interface FailureRule {
623
+ id: string;
624
+ match: (ctx: FailureContext) => {
625
+ failureClass: FailureClass;
626
+ reason: string;
627
+ triggerSpanId?: string;
628
+ triggerEventId?: string;
629
+ } | null;
630
+ }
631
+ declare const DEFAULT_RULES: FailureRule[];
632
+ /** Classify the failure mode of a run using an ordered rule list. */
633
+ declare function classifyFailure(ctx: FailureContext, rules?: FailureRule[]): FailureClassification;
634
+
635
+ /**
636
+ * FailureClusterView — groups failed runs by (failureClass, triggerTool,
637
+ * argHash-prefix) so weekly reviews can prioritize the top-N clusters.
638
+ *
639
+ * Each cluster includes: N runs, scenarios affected, representative
640
+ * error message, a proposed mitigation hint (rule → action table).
641
+ */
642
+
643
+ interface FailureCluster {
644
+ failureClass: FailureClass;
645
+ /** Tool name when the trigger was a tool span, else undefined. */
646
+ toolName?: string;
647
+ /** First 16 chars of argHash — clusters similar args. */
648
+ argPrefix?: string;
649
+ /**
650
+ * Source dimension when the trigger was a judge span (e.g. `'format'`,
651
+ * `'safety'`, `'correctness'`). Lets cross-template aggregators
652
+ * group failures by the dimension that fired without overloading
653
+ * `argPrefix`. Optional — legacy clusters without this field
654
+ * deserialize cleanly.
655
+ */
656
+ dimension?: string;
657
+ runCount: number;
658
+ scenarioIds: string[];
659
+ exampleError?: string;
660
+ exampleRunId: string;
661
+ }
662
+ interface FailureClusterReport {
663
+ clusters: FailureCluster[];
664
+ totalFailures: number;
665
+ totalRuns: number;
666
+ }
667
+ declare function failureClusterView(store: TraceStore, options?: {
668
+ rules?: FailureRule[];
669
+ minClusterSize?: number;
670
+ }): Promise<FailureClusterReport>;
671
+
672
+ /**
673
+ * Reporting helpers — production summaries and paper-quality figures — sit alongside `reporter.ts` rather
674
+ * than replacing it.
675
+ *
676
+ * Three artefacts:
677
+ *
678
+ * - `summaryTable` Markdown table of per-candidate means,
679
+ * 95% bootstrap CIs, BH-adjusted Wilcoxon
680
+ * p-values, and Cohen's d versus a
681
+ * comparator candidate.
682
+ * - `paretoChart` Abstract spec for a cost vs quality
683
+ * scatter, with gate decisions overlaid.
684
+ * Returns numbers + labels — caller
685
+ * chooses the plotting library.
686
+ * - `gainHistogram`
687
+ * Per-item paired holdout deltas as a
688
+ * histogram spec (bins + counts + median +
689
+ * CI). Same "data, not images" contract.
690
+ *
691
+ * The figure types are PlotSpecs — JSON-friendly, library-agnostic.
692
+ * They aren't React components and they aren't PNGs; they are
693
+ * what you'd hand to vega-lite, plotly, matplotlib, or your own
694
+ * Canvas renderer to draw the actual figure.
695
+ */
696
+
697
+ interface SummaryTableOptions {
698
+ /** Comparator candidate id. Wilcoxon + Cohen's d are computed
699
+ * versus this candidate. Required for paired stats columns. */
700
+ comparator?: string;
701
+ /** Which split to read scores from. Default 'holdout'. */
702
+ split?: 'search' | 'holdout';
703
+ /** Confidence level for the bootstrap CI on the mean. Default 0.95. */
704
+ confidence?: number;
705
+ /** FDR for BH adjustment of the comparison p-values. Default 0.05. */
706
+ fdr?: number;
707
+ }
708
+ interface SummaryTableRow {
709
+ candidateId: string;
710
+ n: number;
711
+ mean: number;
712
+ ciLow: number;
713
+ ciHigh: number;
714
+ /** BH-adjusted q-value vs comparator. NaN if no comparator. */
715
+ qValue: number;
716
+ /** Cohen's d vs comparator. NaN if no comparator. */
717
+ cohensD: number;
718
+ }
719
+ interface SummaryTable {
720
+ rows: SummaryTableRow[];
721
+ comparator: string | null;
722
+ split: 'search' | 'holdout';
723
+ /** Pre-rendered markdown — drop into a paper or PR. */
724
+ markdown: string;
725
+ }
726
+ /**
727
+ * Table 1 helper. Buckets runs by `candidateId`, computes mean +
728
+ * bootstrap CI on the chosen split, and (when a comparator is given)
729
+ * BH-adjusted Wilcoxon p + Cohen's d versus that comparator.
730
+ */
731
+ declare function summaryTable(runs: RunRecord[], opts?: SummaryTableOptions): SummaryTable;
732
+ interface ParetoPoint {
733
+ candidateId: string;
734
+ /** Mean USD cost per run on the chosen split. */
735
+ cost: number;
736
+ /** Mean score on the chosen split. */
737
+ quality: number;
738
+ /** Number of runs that informed this point. */
739
+ n: number;
740
+ /** Whether this candidate is on the Pareto frontier — high
741
+ * quality, low cost, no dominator. */
742
+ onFrontier: boolean;
743
+ /** Optional gate verdict for this candidate, if a `GateDecision`
744
+ * for it was passed in. */
745
+ gate?: 'promote' | 'reject_few_runs' | 'reject_negative_delta' | 'reject_overfit_gap' | null;
746
+ }
747
+ interface ParetoFigureSpec {
748
+ kind: 'pareto-cost-quality';
749
+ split: 'search' | 'holdout';
750
+ points: ParetoPoint[];
751
+ axes: {
752
+ x: 'costUsd';
753
+ y: 'score';
754
+ };
755
+ }
756
+ /**
757
+ * Cost vs quality scatter spec. `gateDecisions` is keyed by
758
+ * candidate id; if present, every point picks up the gate verdict
759
+ * for overlay.
760
+ */
761
+ declare function paretoChart(runs: RunRecord[], opts?: {
762
+ split?: 'search' | 'holdout';
763
+ gateDecisions?: Record<string, GateDecision>;
764
+ }): ParetoFigureSpec;
765
+ interface GainDistributionBin {
766
+ /** Inclusive lower edge. */
767
+ lo: number;
768
+ /** Exclusive upper edge (or inclusive if it's the last bin). */
769
+ hi: number;
770
+ /** Number of pairs whose delta lands in this bin. */
771
+ count: number;
772
+ }
773
+ interface GainDistributionFigureSpec {
774
+ kind: 'gain-distribution';
775
+ candidateId: string;
776
+ comparator: string;
777
+ split: 'search' | 'holdout';
778
+ /** Number of pairs used. */
779
+ n: number;
780
+ bins: GainDistributionBin[];
781
+ median: number;
782
+ ci: {
783
+ low: number;
784
+ high: number;
785
+ };
786
+ }
787
+ interface GainDistributionOptions {
788
+ /** Number of histogram bins. Default 11 (so the centre is exact at 0). */
789
+ bins?: number;
790
+ /** Which split to use. Default 'holdout'. */
791
+ split?: 'search' | 'holdout';
792
+ /** Confidence level for the CI. Default 0.95. */
793
+ confidence?: number;
794
+ /** Bootstrap resamples. Default 2000. */
795
+ resamples?: number;
796
+ /** Deterministic seed. */
797
+ seed?: number;
798
+ }
799
+ /**
800
+ * Held-out improvement distribution: per-pair delta (candidate −
801
+ * comparator), histogrammed. Includes the bootstrap CI on the median
802
+ * delta — same primitive the promotion gate uses.
803
+ */
804
+ declare function gainHistogram(runs: RunRecord[], candidateId: string, comparator: string, opts?: GainDistributionOptions): GainDistributionFigureSpec;
805
+ type ResearchReportDecision = 'promote' | 'hold' | 'reject' | 'equivalent' | 'needs_more_data';
806
+ /**
807
+ * Hard floor below which a paired comparison is treated as uninformative
808
+ * regardless of `minPairs`. Mirrors the lower limit on Wilcoxon signed-rank
809
+ * exact tables; below this the test has no power to separate effect sizes.
810
+ */
811
+ declare const RESEARCH_REPORT_HARD_PAIR_FLOOR = 6;
812
+ interface ResearchReportOptions {
813
+ /** Human-readable report title. */
814
+ title?: string;
815
+ /** Comparator candidate id. Required for statistical decision guidance. */
816
+ comparator?: string;
817
+ /** Which split to use for the primary decision. Default 'holdout'. */
818
+ split?: 'search' | 'holdout';
819
+ /** Confidence level used by lower-level report helpers. Default 0.95. */
820
+ confidence?: number;
821
+ /** FDR threshold for q-values. Default 0.05. */
822
+ fdr?: number;
823
+ /**
824
+ * Soft floor on paired observations before issuing a directional
825
+ * promote / reject. Below this we report `needs_more_data` and surface the
826
+ * minimum detectable effect at the current N. Default 20 — chosen so the
827
+ * Wilcoxon signed-rank approximation is reasonable and so the paired
828
+ * bootstrap CI has non-degenerate coverage. Hard floor is enforced at
829
+ * `RESEARCH_REPORT_HARD_PAIR_FLOOR` (6) regardless of this value.
830
+ */
831
+ minPairs?: number;
832
+ /**
833
+ * Region of Practical Equivalence on the paired delta. When a candidate's
834
+ * paired-delta CI is fully contained in `[low, high]`, the decision is
835
+ * `equivalent` rather than `hold`. Sourced from the domain owner — there is
836
+ * no statistically-defensible default.
837
+ */
838
+ rope?: {
839
+ low: number;
840
+ high: number;
841
+ };
842
+ /**
843
+ * Power for the minimum detectable effect (MDE) reported on each candidate.
844
+ * Default 0.8.
845
+ */
846
+ mdePower?: number;
847
+ /**
848
+ * Two-sided alpha for the MDE. Default matches `fdr` so the reported MDE
849
+ * lines up with the test the report actually runs.
850
+ */
851
+ mdeAlpha?: number;
852
+ /** Optional held-out gate decisions keyed by candidate id. */
853
+ gateDecisions?: Record<string, GateDecision>;
854
+ /** Optional failure clusters from failureClusterView. */
855
+ failureClusters?: FailureClusterReport;
856
+ /** Build gain histograms for these candidates. Defaults to all non-comparator candidates. */
857
+ candidateIds?: string[];
858
+ /** Deterministic bootstrap seed passed to gainHistogram and the posterior helper. */
859
+ seed?: number;
860
+ /** Report timestamp. Defaults to current time. */
861
+ generatedAt?: string;
862
+ /**
863
+ * Hash of a preregistered protocol (e.g. `signManifest({...}).contentHash`).
864
+ * Embedded verbatim in the report so the analysis can be cited as the
865
+ * preregistered one rather than a post-hoc fishing expedition.
866
+ */
867
+ preregistrationHash?: string;
868
+ }
869
+ interface ResearchReportRecommendation {
870
+ decision: ResearchReportDecision;
871
+ candidateId: string | null;
872
+ rationale: string[];
873
+ risks: string[];
874
+ nextActions: string[];
875
+ }
876
+ interface ResearchReportCandidate {
877
+ candidateId: string;
878
+ n: number;
879
+ mean: number;
880
+ ciLow: number;
881
+ ciHigh: number;
882
+ qValue: number;
883
+ cohensD: number;
884
+ meanDeltaVsComparator: number | null;
885
+ pairedN: number;
886
+ medianGain: number | null;
887
+ meanGain: number | null;
888
+ gainCi: {
889
+ low: number;
890
+ high: number;
891
+ } | null;
892
+ /**
893
+ * Bayesian-bootstrap-style posterior summaries on the paired delta. Computed
894
+ * from the same resamples that produce the gain CI; interpretable as
895
+ * "fraction of resamples in which the candidate beats the comparator on
896
+ * matched pairs."
897
+ */
898
+ prGreaterThanZero: number | null;
899
+ prInRope: number | null;
900
+ /**
901
+ * Minimum detectable effect (in score units) at the candidate's paired N,
902
+ * the configured power, and the configured alpha. Standardised by the
903
+ * observed paired-delta SD and inverted via `requiredSampleSize`. Reported
904
+ * for every candidate so a `needs_more_data` verdict is actionable.
905
+ */
906
+ mde: number | null;
907
+ onParetoFrontier: boolean;
908
+ gate?: ParetoPoint['gate'];
909
+ decision: ResearchReportDecision;
910
+ decisionReason: string;
911
+ }
912
+ interface ResearchReportMethodology {
913
+ /**
914
+ * Plain-language assumptions the report depends on. Read these first when
915
+ * deciding whether the verdict is load-bearing for a launch decision.
916
+ */
917
+ assumptions: string[];
918
+ /** Tests and estimators the verdict was computed from. */
919
+ methods: string[];
920
+ /** Alternatives the author considered and why this report didn't take them. */
921
+ alternatives: string[];
922
+ /** Failure modes — when this report should NOT drive a decision. */
923
+ whenNotToApply: string[];
924
+ /** Citations for the methodological choices above. */
925
+ citations: string[];
926
+ }
927
+ interface ResearchReport {
928
+ kind: 'agent-eval-research-report';
929
+ title: string;
930
+ generatedAt: string;
931
+ split: 'search' | 'holdout';
932
+ comparator: string | null;
933
+ /**
934
+ * SHA-256 over the canonicalised set of `(runId, candidateId, split)` triples
935
+ * the report was computed from, plus the comparator and split. Stable across
936
+ * key insertion order; recomputable by the reader to verify provenance.
937
+ */
938
+ runFingerprint: string;
939
+ preregistrationHash: string | null;
940
+ rope: {
941
+ low: number;
942
+ high: number;
943
+ } | null;
944
+ executiveSummary: string[];
945
+ recommendation: ResearchReportRecommendation;
946
+ candidates: ResearchReportCandidate[];
947
+ summary: SummaryTable;
948
+ charts: {
949
+ pareto: ParetoFigureSpec;
950
+ gains: GainDistributionFigureSpec[];
951
+ };
952
+ methodology: ResearchReportMethodology;
953
+ failureClusters?: FailureClusterReport;
954
+ markdown: string;
955
+ html: string;
956
+ }
957
+ /**
958
+ * Executive research report for CPO / AI-lead / launch-review consumption.
959
+ *
960
+ * Composes:
961
+ * - `summaryTable` marginal stats with BH-FDR-adjusted q-values
962
+ * - `paretoChart` cost-vs-quality frontier with gate overlay
963
+ * - `gainHistogram` per-candidate paired-delta distribution
964
+ * - paired posterior (this file): bootstrap CI on median, Pr(Δ>0),
965
+ * Pr(Δ∈ROPE), MDE at the configured power
966
+ *
967
+ * Decisions are made on paired evidence — never on marginal means alone —
968
+ * and respect any held-out gate decision the caller passes through. The
969
+ * report embeds a SHA-256 fingerprint of the input run set and, optionally,
970
+ * the hash of a preregistered protocol so a downstream reader can verify
971
+ * provenance and that the analysis was the preregistered one.
972
+ *
973
+ * Async because the fingerprint uses Web Crypto via `hashJson`; deterministic
974
+ * for any fixed `runs`, `seed`, and ROPE.
975
+ */
976
+ declare function researchReport(runs: RunRecord[], opts?: ResearchReportOptions): Promise<ResearchReport>;
977
+
978
+ export { type ResearchReportOptions as $, type ActionableSideInfo as A, type MultiShotTrace as B, type MultiShotTrialResult as C, DEFAULT_RULES as D, type EvolvableVariant as E, type FailureClassification as F, type GainDistributionBin as G, HeldOutGate as H, InMemoryTrialCache as I, type MultiShotVariant as J, type ParetoFigureSpec as K, type ParetoPoint as L, type MutateAdapter as M, type PromptEvolutionConfig as N, type Objective as O, type ParetoResult as P, type PromptEvolutionEvent as Q, type PromptEvolutionResult as R, RESEARCH_REPORT_HARD_PAIR_FLOOR as S, type TrialCache as T, type ReflectionContext as U, type VariantAggregate as V, type ReflectionProposal as W, type ResearchReport as X, type ResearchReportCandidate as Y, type ResearchReportDecision as Z, type ResearchReportMethodology as _, type TrialResult as a, type ResearchReportRecommendation as a0, type ScenarioAggregate as a1, type ScoreAdapter as a2, type SummaryTable as a3, type SummaryTableOptions as a4, type SummaryTableRow as a5, type TrialTrace as a6, buildReflectionPrompt as a7, classifyFailure as a8, crowdingDistance as a9, defaultMultiShotObjectives as aa, dominates as ab, failureClusterView as ac, gainHistogram as ad, paretoChart as ae, paretoFrontier as af, paretoFrontierWithCrowding as ag, parseReflectionResponse as ah, researchReport as ai, runMultiShotOptimization as aj, runPromptEvolution as ak, scalarScore as al, summaryTable as am, trialTraceFromMultiShotTrial as an, type AsiSeverity as b, DEFAULT_MUTATION_PRIMITIVES as c, type Direction as d, type FailureCluster as e, type FailureClusterReport as f, type FailureContext as g, type FailureRule as h, type GainDistributionFigureSpec as i, type GainDistributionOptions as j, type GateDecision as k, type GateEvidence as l, type GenerationReport as m, type HeldOutGateConfig as n, type HeldOutGateRejectionCode as o, type MultiShotGateConfig as p, type MultiShotGateResult as q, type MultiShotMutateAdapter as r, type MultiShotOptimizationConfig as s, type MultiShotOptimizationResult as t, type MultiShotRun as u, type MultiShotRunInput as v, type MultiShotRunner as w, type MultiShotScore as x, type MultiShotScorer as y, type MultiShotSplit as z };