@tangle-network/agent-eval 0.99.0 → 0.100.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/dist/index.js CHANGED
@@ -134,14 +134,14 @@ import {
134
134
  diffFindings,
135
135
  runSemanticConceptJudge
136
136
  } from "./chunk-SJISCGWD.js";
137
- import {
138
- buildDefaultAnalystRegistry,
139
- computeTraceMetrics
140
- } from "./chunk-3NHEO6ZC.js";
141
137
  import {
142
138
  LockedJsonlAppender,
143
139
  Mutex
144
140
  } from "./chunk-DJWX3GVS.js";
141
+ import {
142
+ buildDefaultAnalystRegistry,
143
+ computeTraceMetrics
144
+ } from "./chunk-3NHEO6ZC.js";
145
145
  import {
146
146
  DEFAULT_RUN_SCORE_WEIGHTS,
147
147
  aggregateRunScore,
@@ -2593,6 +2593,59 @@ function printDriverSummary(results) {
2593
2593
  console.log(`${completedCount}/${results.length} personas completed`);
2594
2594
  }
2595
2595
 
2596
+ // src/treatment-gate.ts
2597
+ function gateTreatmentApplied(input, opts = {}) {
2598
+ const failOpen = opts.failOpenWhenNoTelemetry ?? true;
2599
+ let observedTools = 0;
2600
+ let matchedCalls = 0;
2601
+ for (const [tool, count] of Object.entries(input.toolHistogram)) {
2602
+ const n = Number.isFinite(count) && count > 0 ? count : 0;
2603
+ observedTools += n;
2604
+ if (n > 0 && input.matches(tool)) matchedCalls += n;
2605
+ }
2606
+ if (observedTools === 0) {
2607
+ return failOpen ? {
2608
+ applied: true,
2609
+ gated: false,
2610
+ reason: "no tool telemetry captured \u2014 fail-open (not quarantined)",
2611
+ matchedCalls: 0,
2612
+ observedTools: 0
2613
+ } : {
2614
+ applied: false,
2615
+ gated: true,
2616
+ reason: "no tool telemetry captured \u2014 fail-closed",
2617
+ matchedCalls: 0,
2618
+ observedTools: 0
2619
+ };
2620
+ }
2621
+ if (matchedCalls === 0) {
2622
+ return {
2623
+ applied: false,
2624
+ gated: true,
2625
+ reason: `treatment tool never fired (${observedTools} tool calls, 0 matched)`,
2626
+ matchedCalls: 0,
2627
+ observedTools
2628
+ };
2629
+ }
2630
+ return { applied: true, gated: false, matchedCalls, observedTools };
2631
+ }
2632
+ function gateTreatmentFromMetrics(metrics, matches2, opts) {
2633
+ return gateTreatmentApplied({ toolHistogram: metrics.toolHistogram, matches: matches2 }, opts);
2634
+ }
2635
+ function gateTreatmentFromSpans(spans, matches2, opts) {
2636
+ return gateTreatmentFromMetrics(computeTraceMetrics(spans), matches2, opts);
2637
+ }
2638
+ function gateTreatmentFromToolSpans(toolSpans2, matches2, opts) {
2639
+ const toolHistogram = {};
2640
+ for (const s of toolSpans2) {
2641
+ if (s.toolName) toolHistogram[s.toolName] = (toolHistogram[s.toolName] ?? 0) + 1;
2642
+ }
2643
+ return gateTreatmentApplied({ toolHistogram, matches: matches2 }, opts);
2644
+ }
2645
+ function classifyTreatment(_record, gate) {
2646
+ return gate.gated ? "treatment-not-applied" : "measurable";
2647
+ }
2648
+
2596
2649
  // src/anti-slop.ts
2597
2650
  var DEFAULT_HEDGES = [
2598
2651
  /\bi\s+could\s+be\s+wrong\b/i,
@@ -3922,6 +3975,97 @@ var BudgetGuard = class {
3922
3975
  }
3923
3976
  };
3924
3977
 
3978
+ // src/hidden-criteria-grading.ts
3979
+ var hiddenDestinations = /* @__PURE__ */ new Set([
3980
+ "grading-only",
3981
+ "judge-only"
3982
+ ]);
3983
+ function isHiddenDestination(destination) {
3984
+ return hiddenDestinations.has(destination);
3985
+ }
3986
+ function routeFields(routing, values) {
3987
+ const out = [];
3988
+ for (const name of Object.keys(routing)) {
3989
+ const value = values[name];
3990
+ if (value === void 0) {
3991
+ throw new ValidationError(
3992
+ `routed field "${name}" has a destination but no value \u2014 every routed field must carry its value`
3993
+ );
3994
+ }
3995
+ out.push({ name, value, destination: routing[name] });
3996
+ }
3997
+ return out;
3998
+ }
3999
+ function assertNoHiddenLeak(fields, agentContext, opts = {}) {
4000
+ const minLen = opts.minMatchLength ?? 12;
4001
+ const leaks = [];
4002
+ for (const field of fields) {
4003
+ if (!isHiddenDestination(field.destination)) continue;
4004
+ const needle = field.value.trim();
4005
+ if (needle.length < minLen) continue;
4006
+ if (agentContext.includes(needle)) {
4007
+ leaks.push({ field: field.name, destination: field.destination });
4008
+ }
4009
+ }
4010
+ if (leaks.length > 0) {
4011
+ const detail = leaks.map((l) => `"${l.field}" (${l.destination})`).join(", ");
4012
+ throw new ValidationError(
4013
+ `hidden-criteria firewall breached: ${leaks.length} hidden field(s) reached the agent context: ${detail}`
4014
+ );
4015
+ }
4016
+ return fields;
4017
+ }
4018
+ function agentVisibleFields(fields) {
4019
+ return fields.filter((f) => !isHiddenDestination(f.destination));
4020
+ }
4021
+ function hiddenGrade(passed, total, notes) {
4022
+ const p = Number.isFinite(passed) && passed > 0 ? Math.floor(passed) : 0;
4023
+ const t = Number.isFinite(total) && total > 0 ? Math.floor(total) : 0;
4024
+ const passRate = t > 0 ? Math.min(1, p / t) : 0;
4025
+ return { passed: Math.min(p, t > 0 ? t : p), total: t, passRate, notes };
4026
+ }
4027
+ async function gradeOnHidden(args) {
4028
+ assertNoHiddenLeak(args.firewall.fields, args.firewall.agentContext, args.firewall.options);
4029
+ const result = await args.grader(args.artifact, args.hiddenCriteria, args.signal);
4030
+ return hiddenGrade(result.passed, result.total, result.notes);
4031
+ }
4032
+ var defaultBlendWeights = { heldout: 0.7, judge: 0.3 };
4033
+ function normalizeWeights(weights) {
4034
+ const h = Number.isFinite(weights.heldout) && weights.heldout >= 0 ? weights.heldout : 0;
4035
+ const j = Number.isFinite(weights.judge) && weights.judge >= 0 ? weights.judge : 0;
4036
+ const sum3 = h + j;
4037
+ if (sum3 <= 0) {
4038
+ throw new ValidationError(
4039
+ "blend weights must have a positive sum (got heldout+judge <= 0) \u2014 cannot weight a composite by zero"
4040
+ );
4041
+ }
4042
+ return { heldout: h / sum3, judge: j / sum3 };
4043
+ }
4044
+ function blendHeldout(heldoutPassRate, judgeScore, weights = defaultBlendWeights) {
4045
+ const w = normalizeWeights(weights);
4046
+ const heldout = clampUnit(heldoutPassRate);
4047
+ const judge = clampUnit(judgeScore);
4048
+ return w.heldout * heldout + w.judge * judge;
4049
+ }
4050
+ function withHeldoutBlend(score, heldoutPassRate, weights = defaultBlendWeights) {
4051
+ return async (input) => {
4052
+ const base = await score(input);
4053
+ if (base.failed) return base;
4054
+ const rate = clampUnit(heldoutPassRate(input.artifact));
4055
+ const composite = blendHeldout(rate, base.composite, weights);
4056
+ const w = normalizeWeights(weights);
4057
+ return {
4058
+ ...base,
4059
+ composite,
4060
+ notes: `composite=${composite.toFixed(3)} (held-out ${(rate * 100).toFixed(0)}% \xD7 ${w.heldout.toFixed(2)} + quality ${base.composite.toFixed(3)} \xD7 ${w.judge.toFixed(2)})` + (base.notes ? ` \u2014 ${base.notes}` : "")
4061
+ };
4062
+ };
4063
+ }
4064
+ function clampUnit(value) {
4065
+ if (!Number.isFinite(value)) return 0;
4066
+ return Math.max(0, Math.min(1, value));
4067
+ }
4068
+
3925
4069
  // src/cost-ledger.ts
3926
4070
  function modelPriceKey(model) {
3927
4071
  return isModelPriced(model) ? model : null;
@@ -10027,6 +10171,7 @@ export {
10027
10171
  agentProfileHash,
10028
10172
  agentProfileId,
10029
10173
  agentProfileModelId,
10174
+ agentVisibleFields,
10030
10175
  aggregateJudgeVerdicts,
10031
10176
  aggregateLlm,
10032
10177
  aggregatePrReviewScore,
@@ -10042,6 +10187,7 @@ export {
10042
10187
  assertCrossFamily,
10043
10188
  assertLlmRoute,
10044
10189
  assertModelsServed,
10190
+ assertNoHiddenLeak,
10045
10191
  assertRealBackend,
10046
10192
  assertRecordIntegrity,
10047
10193
  assertReleaseConfidence,
@@ -10058,6 +10204,7 @@ export {
10058
10204
  benchmarks_exports as benchmarks,
10059
10205
  benjaminiHochberg,
10060
10206
  bisect,
10207
+ blendHeldout,
10061
10208
  blockingKnowledgeEval,
10062
10209
  bonferroni,
10063
10210
  bootstrapCi,
@@ -10092,6 +10239,7 @@ export {
10092
10239
  clamp01,
10093
10240
  classifyEuAiRisk,
10094
10241
  classifyFailure,
10242
+ classifyTreatment,
10095
10243
  cliffsDelta,
10096
10244
  codeExecutionJudge,
10097
10245
  cohensD,
@@ -10145,6 +10293,7 @@ export {
10145
10293
  decideNextUserTurn,
10146
10294
  decideReferenceReplayPromotion,
10147
10295
  decideReferenceReplayRunPromotion,
10296
+ defaultBlendWeights,
10148
10297
  defaultIsMaterial,
10149
10298
  defaultJudges,
10150
10299
  defaultParseStudentLabel,
@@ -10210,9 +10359,14 @@ export {
10210
10359
  formatScorecardDiff,
10211
10360
  gainHistogram,
10212
10361
  gatePerf,
10362
+ gateTreatmentApplied,
10363
+ gateTreatmentFromMetrics,
10364
+ gateTreatmentFromSpans,
10365
+ gateTreatmentFromToolSpans,
10213
10366
  ghCliClient,
10214
10367
  gitProvenanceReader,
10215
10368
  precision as goldenPrecision,
10369
+ gradeOnHidden,
10216
10370
  gradeSemanticStatus,
10217
10371
  groupBy,
10218
10372
  groupRunsByAgentProfileCell,
@@ -10220,6 +10374,7 @@ export {
10220
10374
  hashJson,
10221
10375
  hashScenarios,
10222
10376
  hashToUnit,
10377
+ hiddenGrade,
10223
10378
  htmlContainsElement,
10224
10379
  httpGithubClient,
10225
10380
  improvementVerdict,
@@ -10233,6 +10388,7 @@ export {
10233
10388
  interRaterReliability,
10234
10389
  interpretCliffs,
10235
10390
  iqr,
10391
+ isHiddenDestination,
10236
10392
  isJudgeSpan,
10237
10393
  isLlmSpan,
10238
10394
  isModelPriced,
@@ -10351,6 +10507,7 @@ export {
10351
10507
  resolveModelPricing,
10352
10508
  resolveSeat,
10353
10509
  roundTripRunRecord,
10510
+ routeFields,
10354
10511
  rowCount,
10355
10512
  rowWhere,
10356
10513
  runAgentControlLoop,
@@ -10449,6 +10606,7 @@ export {
10449
10606
  wilcoxonSignedRank,
10450
10607
  wilson,
10451
10608
  withAssignedFeedbackSplit,
10609
+ withHeldoutBlend,
10452
10610
  withJudgeRetry,
10453
10611
  withOtelPipeline,
10454
10612
  wranglerDeployRunner