@tangle-network/agent-eval 0.82.0 → 0.84.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
@@ -6,6 +6,10 @@ import {
6
6
  parseCorrectnessResponse,
7
7
  verifyCompletion
8
8
  } from "./chunk-YGYXHNAQ.js";
9
+ import {
10
+ parseRuntimeTrajectoryHookEvent,
11
+ projectRuntimeTrajectoryEvidence
12
+ } from "./chunk-T4SQEITX.js";
9
13
  import {
10
14
  HoldoutAuditor,
11
15
  canaryLeakView,
@@ -2911,14 +2915,14 @@ async function runHarnessExperiment(config) {
2911
2915
  const score = config.score ?? ((trace) => critic.scoreTrace(trace));
2912
2916
  const results = await mapLimit(jobs, config.parallelism ?? 1, async (request) => {
2913
2917
  const trace = await config.adapter.run(request);
2914
- const runScore2 = await score(trace, request);
2918
+ const runScore3 = await score(trace, request);
2915
2919
  const result = {
2916
2920
  variant: request.variant,
2917
2921
  scenario: request.scenario,
2918
2922
  trialIndex: request.trialIndex,
2919
2923
  trace,
2920
- score: runScore2,
2921
- aggregate: aggregateRunScore(runScore2, config.weights)
2924
+ score: runScore3,
2925
+ aggregate: aggregateRunScore(runScore3, config.weights)
2922
2926
  };
2923
2927
  await config.onResult?.(result);
2924
2928
  return result;
@@ -7089,6 +7093,121 @@ function createDefaultReviewer(options) {
7089
7093
  };
7090
7094
  }
7091
7095
 
7096
+ // src/description-length-gate.ts
7097
+ import { gzipSync } from "zlib";
7098
+ function runScore2(run) {
7099
+ const o = run.outcome;
7100
+ const s = o.holdoutScore ?? o.searchScore ?? o.raw?.score;
7101
+ return typeof s === "number" && Number.isFinite(s) ? s : void 0;
7102
+ }
7103
+ function taskKey(run) {
7104
+ return run.scenarioId ?? run.experimentId;
7105
+ }
7106
+ function perTaskMeanScore(runs) {
7107
+ const acc = /* @__PURE__ */ new Map();
7108
+ for (const run of runs) {
7109
+ const s = runScore2(run);
7110
+ if (s === void 0) continue;
7111
+ const key = taskKey(run);
7112
+ const cur = acc.get(key) ?? { sum: 0, n: 0 };
7113
+ cur.sum += s;
7114
+ cur.n += 1;
7115
+ acc.set(key, cur);
7116
+ }
7117
+ return new Map([...acc].map(([k, v]) => [k, v.sum / v.n]));
7118
+ }
7119
+ function modelDescriptionBits(content) {
7120
+ return gzipSync(Buffer.from(content, "utf8")).byteLength * 8;
7121
+ }
7122
+ function dataDescriptionBits(scoreByTask, keys, scoreFloor) {
7123
+ let bits = 0;
7124
+ for (const key of keys) {
7125
+ const s = scoreByTask.get(key);
7126
+ if (s === void 0) continue;
7127
+ bits += -Math.log2(Math.max(s, scoreFloor));
7128
+ }
7129
+ return bits;
7130
+ }
7131
+ var DescriptionLengthGate = class {
7132
+ baselineKey;
7133
+ lambda;
7134
+ marginBits;
7135
+ scoreFloor;
7136
+ minTasks;
7137
+ constructor(config) {
7138
+ if (!config.baselineKey) throw new Error("DescriptionLengthGate: baselineKey is required");
7139
+ this.baselineKey = config.baselineKey;
7140
+ this.lambda = config.lambda ?? 1;
7141
+ this.marginBits = config.marginBits ?? 0;
7142
+ this.scoreFloor = config.scoreFloor ?? 2 ** -10;
7143
+ this.minTasks = config.minTasks ?? 3;
7144
+ if (!(this.lambda >= 0)) throw new Error("DescriptionLengthGate: lambda must be \u2265 0");
7145
+ if (!(this.scoreFloor > 0 && this.scoreFloor < 1))
7146
+ throw new Error("DescriptionLengthGate: scoreFloor must be in (0,1)");
7147
+ }
7148
+ /** Decide whether `candidate` should replace `baseline`. Both are scored on
7149
+ * the shared task set (the enlarged evidence); the candidate promotes only
7150
+ * if λ·L_model + L_data is strictly lower by at least `marginBits`. */
7151
+ evaluate(candidate, baseline) {
7152
+ const candidateId = inferCandidateId(candidate.runs, this.baselineKey);
7153
+ const candScores = perTaskMeanScore(candidate.runs);
7154
+ const baseScores = perTaskMeanScore(baseline.runs);
7155
+ const shared = [...candScores.keys()].filter((k) => baseScores.has(k));
7156
+ const modelBits = {
7157
+ candidate: this.lambda * modelDescriptionBits(candidate.content),
7158
+ baseline: this.lambda * modelDescriptionBits(baseline.content)
7159
+ };
7160
+ const dataBits = {
7161
+ candidate: dataDescriptionBits(candScores, shared, this.scoreFloor),
7162
+ baseline: dataDescriptionBits(baseScores, shared, this.scoreFloor)
7163
+ };
7164
+ const totalBits = {
7165
+ candidate: modelBits.candidate + dataBits.candidate,
7166
+ baseline: modelBits.baseline + dataBits.baseline
7167
+ };
7168
+ const evidence = {
7169
+ tasks: shared.length,
7170
+ modelBits,
7171
+ dataBits,
7172
+ totalBits,
7173
+ deltaBits: totalBits.candidate - totalBits.baseline,
7174
+ modelBitsDelta: modelBits.candidate - modelBits.baseline,
7175
+ dataBitsDelta: dataBits.candidate - dataBits.baseline
7176
+ };
7177
+ const base = { candidateId, baselineId: this.baselineKey, evidence };
7178
+ const fmt2 = (n) => n.toFixed(1);
7179
+ if (shared.length < this.minTasks) {
7180
+ return {
7181
+ ...base,
7182
+ promote: false,
7183
+ reason: `few_tasks: ${shared.length} shared task(s) < min ${this.minTasks}`,
7184
+ rejectionCode: "few_tasks"
7185
+ };
7186
+ }
7187
+ if (!(evidence.deltaBits < -this.marginBits)) {
7188
+ const code = evidence.dataBitsDelta < 0 ? "model_bloat" : "no_total_gain";
7189
+ const why = code === "model_bloat" ? `model grew ${fmt2(evidence.modelBitsDelta)} bits, outpacing a ${fmt2(-evidence.dataBitsDelta)}-bit data gain` : `outcomes did not improve (data \u0394=${fmt2(evidence.dataBitsDelta)} bits)`;
7190
+ return {
7191
+ ...base,
7192
+ promote: false,
7193
+ reason: `${code}: total \u0394=${fmt2(evidence.deltaBits)} bits does not clear the ${fmt2(this.marginBits)}-bit margin \u2014 ${why}`,
7194
+ rejectionCode: code
7195
+ };
7196
+ }
7197
+ return {
7198
+ ...base,
7199
+ promote: true,
7200
+ reason: `promote: total \u0394=${fmt2(evidence.deltaBits)} bits (model \u0394=${fmt2(evidence.modelBitsDelta)}, data \u0394=${fmt2(evidence.dataBitsDelta)}) over ${shared.length} tasks`,
7201
+ rejectionCode: null
7202
+ };
7203
+ }
7204
+ };
7205
+ function inferCandidateId(runs, baselineKey) {
7206
+ for (const run of runs)
7207
+ if (run.candidateId && run.candidateId !== baselineKey) return run.candidateId;
7208
+ return runs[0]?.candidateId ?? "(unknown candidate)";
7209
+ }
7210
+
7092
7211
  // src/discover-personas.ts
7093
7212
  import { promises as fs } from "fs";
7094
7213
  import { basename, extname, join as join3 } from "path";
@@ -7240,7 +7359,7 @@ var HeldOutGate = class {
7240
7359
  * the candidate run with the matching baseline run. Pairs without
7241
7360
  * a holdout score on both sides are dropped. */
7242
7361
  evaluate(candidate, baseline) {
7243
- const candidateId = inferCandidateId(candidate, this.baselineKey);
7362
+ const candidateId = inferCandidateId2(candidate, this.baselineKey);
7244
7363
  const baselineId = this.baselineKey;
7245
7364
  const baselineHoldoutByKey = indexHoldoutByKey(baseline);
7246
7365
  const beforeHoldout = [];
@@ -7343,7 +7462,7 @@ var HeldOutGate = class {
7343
7462
  };
7344
7463
  }
7345
7464
  };
7346
- function inferCandidateId(candidate, baselineKey) {
7465
+ function inferCandidateId2(candidate, baselineKey) {
7347
7466
  for (const run of candidate) {
7348
7467
  if (run.candidateId && run.candidateId !== baselineKey) return run.candidateId;
7349
7468
  }
@@ -8314,6 +8433,7 @@ export {
8314
8433
  DEFAULT_TRACE_ANALYST_BUDGETS,
8315
8434
  DEFAULT_TRACE_ANALYST_KINDS,
8316
8435
  Dataset,
8436
+ DescriptionLengthGate,
8317
8437
  DockerSandboxDriver,
8318
8438
  DualAgentBench,
8319
8439
  ERROR_COUNT_PATTERNS,
@@ -8485,6 +8605,7 @@ export {
8485
8605
  createTraceAnalystKind,
8486
8606
  crossTraceDiff,
8487
8607
  crowdingDistance,
8608
+ dataDescriptionBits,
8488
8609
  decideNextUserTurn,
8489
8610
  decideReferenceReplayPromotion,
8490
8611
  decideReferenceReplayRunPromotion,
@@ -8591,6 +8712,7 @@ export {
8591
8712
  matchGoldens,
8592
8713
  mergeLayerResults,
8593
8714
  mergeSteeringBundle,
8715
+ modelDescriptionBits,
8594
8716
  multiToolchainLayer,
8595
8717
  nistAiRmfReport,
8596
8718
  normalizeScores,
@@ -8613,6 +8735,7 @@ export {
8613
8735
  parseGoldJsonl,
8614
8736
  parseReflectionResponse,
8615
8737
  parseRunRecordSafe,
8738
+ parseRuntimeTrajectoryHookEvent,
8616
8739
  partialCredit,
8617
8740
  passOrthogonality,
8618
8741
  pixelDeltaRatio,
@@ -8623,6 +8746,7 @@ export {
8623
8746
  probeLlm,
8624
8747
  profile_exports as profile,
8625
8748
  projectOtlpFlatLine,
8749
+ projectRuntimeTrajectoryEvidence,
8626
8750
  promptBisect,
8627
8751
  proposeAutomatedPullRequest,
8628
8752
  proposeSynthesisTargets,